按register_post_type函数按我想要的方式操作



我正在WordPress中创建自己的帖子。然而,我遇到了一个小问题,我不知道如何解决它。

好吧,所以第一件事。我创建了2个新的帖子类型(bc我想设计不同于常规帖子(

所以我总共有3种类型的帖子:

"Post"(wordpress默认(

"审查">

"最佳">

问题在于创建类别和子类别时。并将其分配给默认帖子。

url显示良好:www.domainName.com/Category/Subcategory/postname/

如何甚至无论我做什么我的新帖子类型

它们显示为:

www.domainName.com/Review/post-name/

www.domainName.com/best/post-name/

我希望它们具有与默认帖子相同的行为。

因此,当我创建一个新的帖子评论时:我希望网址是:www.domainName.com/category/sub-category/post-name/

function toolsyouwishfor_post_types() {
// Best Post Type
register_post_type( 'best', array(
'rewrite' => array('slug' => 'category'),
'supports' => array('title','editor', 'excerpt','thumbnail','custom-fields','post-formats'),
'taxonomies'  => array( 'category' ),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Best Type Posts',
'add_new_item' => 'Add New Best Type Post',
'edit_item' => 'Edit Best Type Post Post',
'all_items' => 'All Best Posts',
'singular_name' => 'Best Post'
)  
));
// Review Post Type
register_post_type( 'review', array(
'rewrite' => array('slug' => 'category'),
'supports' => array('title','editor', 'excerpt','thumbnail','custom-fields','post-formats'),
'taxonomies'  => array( 'category' ),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Review Post',
'add_new_item' => 'Add New Review',
'edit_item' => 'Edit Review Post',
'all_items' => 'All Review Posts',
'singular_name' => 'Review Post'
)  
));
// 'rewrite' => array('slug' => 'courses/%course%'),
}

add_action('init', 'toolsyouwishfor_post_types');

我找到了使用这个插件的方法:https://wordpress.org/plugins/custom-post-type-permalinks/

安装它,然后转到"工具">"永久链接"页面。向下滚动到您的帖子类型下的"自定义帖子类型的永久链接设置"下,将您要将此属性设置为的每个帖子类型的/%postname%/更改为/%category%/%postname%/。在屏幕截图中,帖子类型称为cpt_services。参见屏幕截图:

屏幕截图1

最新更新