Php 如何在wordpress中将分类ID添加到其slug中?
我注册了一个自定义帖子类型及其分类,如下所示:Php 如何在wordpress中将分类ID添加到其slug中?,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我注册了一个自定义帖子类型及其分类,如下所示: function book() { register_post_type('book', array( 'labels' => array( 'name' => __('Book'), 'add_new_item' => "Add New", 'edit_item' => __('Edit'), 'new_
function book() {
register_post_type('book', array(
'labels' => array(
'name' => __('Book'),
'add_new_item' => "Add New",
'edit_item' => __('Edit'),
'new_item' => __('New'),
'all_items' => __('All'),
'view_item' => __('View'),
'search_items' => __('Search'),
'not_found' => __('Not found'),
'not_found_in_trash' => __('Not anything found in the Trash'),
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicy_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 20,
//'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
//'menu_icon' => 'dashicons-book-alt3',
'hierarchical' => TRUE,
'query_var' => true,
'supports' => array(
'title', 'editor', 'thumbnail'
),
'rewrite' => array('slug' => 'book', 'with_front' => false),
'taxonomies' => array('post_tag'),
'can_export' => true,
'description' => __('Book')
)
);
}
function book_taxonomy() {
register_taxonomy(
'book_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'book', //post type name
array(
'hierarchical' => true,
'label' => 'Book Cat', //Display name
'query_var' => true,
'show_in_nav_menus' => true,
'rewrite' => array(
'slug' => 'book/c', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action('init', 'book');
add_action('init', 'book_taxonomy');
此代码正在运行。
分类链接类似于:
但我只想在该链接中添加分类ID,如:
“121”是分类链接。
有什么办法可以这样做吗?非常感谢 为您提供术语slug:例如:术语slug示例
$slug = $term->slug;
$field(string)(必选)“id”、“slug”、“name”或“term\u taxonomy\u id”默认值:“id”非常感谢您的帮助。我使用了这个插件,我可以在Catgory中更改总链接。