如何解决如何在URL自定义帖子类型中显示所有类别和子类别
我正在尝试在自定义帖子类型的URL中显示类别。
示例:
website.com/custom-post-type/main-category/sub-category/post-name
当前,URL仅显示第一类。如何使所有类别显示在帖子永久链接中?
这是我到目前为止所拥有的
自定义帖子类型:
add_action( 'init','create_post_type' );
function create_post_type() {
register_post_type( 'system',array(
'labels' => array(
'name' => __( 'Systems' ),'singular_name' => __( 'System' )
),'capability_type' => 'post','supports' => array('title','editor','comments'),'public' => true,'has_archive' => true,'rewrite' => array( 'slug' => '/system/%category%' ),'taxonomies' => array('category')
)
);
}
更改固定链接的功能
function url_category( $post_link,$id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID,'category' );
$urlp = $terms[0]->slug;
if( $terms ){
return str_replace( '%category%',$urlp,$post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link','url_category',1,3 );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。