我有一个自定义的帖子类型,即services
&;自定义分类法services_type
我的自定义永久链接结构为/%类别%/%postname%
term1,term2,term3
在services\\u type taxonomy下有不同的术语;post1,post2,post3,post4
是帖子
我我想知道的是
http://example.com/term1/post1
http://example.com/term1/post2
http://example.com/term2/post3
http://example.com/term3/post4
但现在他们是
http://example.com/services/post1以下是我到目前为止使用的内容
function wpt_services_posttype() {
register_post_type( \'services\',
array(
\'labels\' => array(
\'name\' => __( \'Services\' ),
),
\'public\' => true,
\'supports\' => array( \'title\',\'editor\',\'thumbnail\',\'page-attributes\',\'custom-fields\'),
\'capability_type\' => \'post\',
\'rewrite\' => array("slug" => "services/%services_type%"), // Permalinks format
\'menu_position\' => 6,
\'show_ui\'=>true,
\'query_var\'=>true
)
);
}
add_action( \'init\', \'wpt_services_posttype\' );
//code for adding texonomy
function services_init() {
// create a new taxonomy
register_taxonomy(
\'services_type\',
\'services\',
array(
\'labels\' => array(
\'name\'=>\'services type\',
\'add_new_item\'=>\'Add New type \',
\'new_item_name\'=>"New type" ,
),
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'hierarchical\' => true,
\'rewrite\' => array( \'slug\' => \'services\' ),
)
);
}
add_action( \'init\', \'services_init\' );
add_filter(\'post_type_link\', \'services_permalink_structure\', 10, 4);
function services_permalink_structure($post_link, $post, $leavename, $sample)
{
if ( false !== strpos( $post_link, \'%services_type%\' ) ) {
$service_type_term = get_the_terms( $post->ID, \'service_type\' );
$post_link = str_replace( \'%services_type%\', array_pop( $service_type_term )->slug, $post_link );
}
return $post_link;
}
我尝试了各种代码,但我没有接近它。
请帮忙