简体   繁体   English

具有自定义帖子类型和自定义分类的WordPress永久链接

[英]WordPress Permalink with custom post type and custom taxonomy

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. 我有一个名为product的自定义帖子类型,以及一个名为product_types的产品的自定义分类法,它是分层的,因此我有子类别。

I want the permalink to show up as http://mysite.com/product_type/sub_category/postname 我希望固定链接显示为http://mysite.com/product_type/sub_category/postname

I tried a lot of plugins and things I found online, nothing worked so far. 我尝试了很多插件和在网上找到的东西,到目前为止没有任何效果。

Thank you. 谢谢。

firstly I would double check the function which is creating your custom post type, within that function there should be an element called: rewrite 首先,我会仔细检查正在创建您的自定义帖子类型的函数,在该函数中应该有一个名为:rewrite的元素

ie: 即:

register_post_type( 'products',
   'menu_position' => 25, // below pages
   'public' => true,
   'show_ui' => true,
   'rewrite' => array( 'slug' => 'product' ) <-- this is what you need!
);

also check the register_taxonomy function for the same! 还要检查register_taxonomy函数是否相同!

ie: 即:

 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!
  )); 

the only thing left to check is: 唯一需要检查的是:

your permalink structure is set to /%postname%/ you may have to reset to default, save it, then re-set to /%postname%/ and save, 您的永久链接结构设置为/%postname%/,您可能必须重置为默认值,将其保存,然后重新设置为/%postname%/并保存,

hope that helps :) 希望能有所帮助:)

Marty 马蒂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM