在我的 WordPress 主题的 functions.php
中,我创建了一个名为 foobar
的自定义帖子类型。
是否可以重新使用 foobar 帖子的默认
类别和标签?或者我是否必须创建两个分类法:
- 一个类别
- 另一个用于标签
要实现这个目标吗?
编辑:我想我已经通过在创建自定义帖子类型的函数中使用此代码解决了这个问题:
register_taxonomy_for_object_type('category', 'foobar');
register_taxonomy_for_object_type('post_tag', 'foobar');
最佳答案
当 registering the post type 时,您可以用一 block 石头杀死两只鸟并使用taxonomies
键。 :
$product_labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name'),
'add_new' => _x('Add New', 'portfolio item'),
'add_new_item' => __('Add New Product'),
'edit_item' => __('Edit Product'),
'new_item' => __('New Product'),
'view_item' => __('View Product'),
'search_items' => __('Search Products'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$product_args = array(
'labels' => $product_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'product'),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 2,
'supports' => array('title','editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'page-attributes', 'custom-fields', ),
// Set the available taxonomies here
'taxonomies' => array('category', 'post_tag')
);
register_post_type('product', $product_args);
关于wordpress - 重新使用自定义帖子类型的默认类别/标签分类法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6258996/