我有几种帖子类型都使用与帖子共享的“类别”分类法。
这是通过将
'taxonomies' => array( 'category' )
添加到我的register_post_type();
来完成的
完整代码:
add_action('init', 'brand_register');
function brand_register() {
$labels = array(
'name' => 'Brand',
'singular_name' => 'Brands',
'add_new' => 'Add New',
'add_new_item' => 'Add New',
'edit_item' => 'Edit',
'new_item' => 'New',
'all_items' => 'All',
'view_item' => 'View',
'search_items' => 'Search',
'not_found' => 'Nothing found',
'not_found_in_trash' => 'Nothing found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Brands'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'post-formats' ),
'taxonomies' => array( 'category' ),
);
register_post_type('brand' , $args);
flush_rewrite_rules();
}
我的问题:
这一切都在前端工作,但在后端我得到错误。
如果将“帖子”分配给类别“Apple”并将“品牌”(帖子类型)分配给类别“Apple”,当我在管理员的帖子概述中按类别过滤时,它会抛出错误并且不起作用.
我查看了
wp_dropdown_categories()
的代码,没有post-type选项。因此,当应用过滤器时,它会尝试将所有“帖子”和所有“品牌”帖子类型一起过滤,但我在“帖子”概述页面上。
我知道一个解决方案可能是为“乐队”帖子类型创建一个新的分类法。但这并没有按照我在前端的方式对它们进行归档/分类。如果这种帖子类型在后端无法正常工作,为什么我什至可以允许它具有与“帖子”相同的分类法?
有没有其他人遇到过这种情况或有解决方案?