问题描述
示例:
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 (将#修改为@)