具有自定义帖子类型和自定义分类法的 WordPress 永久链接
我有一个名为 product 的自定义帖子类型和一个名为 product_types 的产品自定义分类法,它是分层的,所以我有子类别.
I have a custom post type called product and a custom taxonomy for products called product_types, which is hierarchical, so I have sub-categories in it.
我希望永久链接显示为 http://mysite.com/product_type/sub_category/postname
I want the permalink to show up as http://mysite.com/product_type/sub_category/postname
我尝试了很多插件和我在网上找到的东西,到目前为止没有任何效果.
I tried a lot of plugins and things I found online, nothing worked so far.
谢谢.
首先我会仔细检查创建自定义帖子类型的函数,在该函数中应该有一个元素叫做:rewrite
firstly I would double check the function which is creating your custom post type, within that function there should be an element called: rewrite
即:
register_post_type( 'products',
'menu_position' => 25, // below pages
'public' => true,
'show_ui' => true,
'rewrite' => array( 'slug' => 'product' ) <-- this is what you need!
);
同样检查 register_taxonomy 函数!
also check the register_taxonomy function for the same!
即:
register_taxonomy(
'team',array('product_types'),
array(
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'hierarchical' => true, <-- this is needed!
'rewrite' => true <-- this is what you need!
));
唯一需要检查的是:
您的永久链接结构设置为/%postname%/您可能必须重置为默认值,保存它,然后重新设置为/%postname%/并保存,
your permalink structure is set to /%postname%/ you may have to reset to default, save it, then re-set to /%postname%/ and save,
希望有帮助:)
马蒂