在我的wordpress主题的functions.php中,我创建了一个名为foobar的自定义帖子类型。是否可以对foobar帖子重新使用默认类别和标签?还是我必须创建两个分类法(一个用于类别,另一个用于标签)才能实现?
编辑:我想我已经通过在创建自定义帖子类型的函数中使用此代码解决了此问题:
register_taxonomy_for_object_type('category', 'foobar');
register_taxonomy_for_object_type('post_tag', 'foobar');
我掌管。
最佳答案
您可以用一块石头杀死两只鸟,并在registering the post type时使用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);