【发布时间】:2021-03-28 15:08:29
【问题描述】:
我有一个自定义分类设置,称为产品类别。如果我创建一个类别,例如“Cattle”并将 slug 设置为 /cattle/ - 当我转到 site.com/product-category/cattle 时它工作正常。
但是,如果我随后进入 wp-admin,并将类别的 slug 编辑为 /cattle-feed/,则此特定类别的所有链接仍显示为 /cattle/ - 都在管理面板中(如果我在类别上单击“查看”),在 wp 菜单中,在使用“get_category_link()”时在前端。
/cattle/ 变成 404 (它应该)。 /cattle-feed/ 成为正确的分类类别档案(它应该)。 admin、wp-menu 和前端的所有链接转到 /cattle/,但正确设置为 /cattle-feed/
这是分类代码:
add_action( 'init', 'west_create_products_category_taxonomy', 0 );
//create a custom taxonomy name it subjects for your posts
function west_create_products_category_taxonomy() {
$labels = array(
'name' => _x( 'Product Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Product Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Product Categories' ),
);
// Now register the taxonomy
register_taxonomy('product_category',array('products', 'post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'product-category' ),
));
}
我已尝试刷新永久链接。我在这里错过了什么?
【问题讨论】:
-
您是否再次尝试保存永久链接?在设置>永久链接中将永久链接结构更改为默认并保存更改,再次将其更改为帖子名称或自定义结构并再次保存。
-
“我试过刷新永久链接。” = 再次保存永久链接。我也试过 flush_rewrite_rules()
标签: wordpress permalinks slug custom-taxonomy