我创建了自定义帖子类型product
并添加了分类法product_category
为了它,用hierarchical
设置为true,因为我需要父类别(用例:水果>浆果等)。的管理员列表product
(/wp admin/edit.php?post\\u type=product)仅显示具有父分类法的产品,而不显示具有子分类法的产品,即使product
s显示正确的数字
导航到wp admin/edit时。php?product\\u category=浆果;post\\u type=product,它显示缺少的帖子。
我做错了什么?以下是责任代码:
$taxonomy = [
\'hierarchical\' => true,
\'labels\' => [ ... ],
\'show_ui\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => true,
\'refersTo\' => \'product\'
];
$postType = [
\'labels\' => [ ... ],
\'supports\' => [
\'title\',
\'editor\',
\'thumbnail\',
\'custom-fields\',
\'revisions\'
],
\'taxonomies\' => [ \'product_category\' ],
\'rewrite\' => true,
\'public\' => true,
\'has_archive\' => true
];
function flush_rewrite_rules () {
global $wp_rewrite;
$wp_rewrite->flush_rules();
});
add_action(\'init\', \'flush_rewrite_rules\' );
function register_products_taxonomy () {
register_taxonomy( \'product_category\', \'product\', $taxonomy);
flush_rewrite_rules();
}
add_action( \'init\', \'register_products_taxonomy\', 5 )
function register_products_type () {
register_post_type( \'product\', $postType );
flush_rewrite_rules();
}
add_action( \'init\', \'register_products_type\' );
SO网友:Picard
这并不完全是答案,但在这里,它的格式会比在评论部分更好。
为了解决您的问题,我将从最简单的工作集开始。然后逐行扩展解决方案,检查它在每个步骤后是否仍然有效。您可以从以下内容开始:
function custom_post_types() {
$args = array(
\'public\' => true,
\'label\' => \'Products\'
);
register_post_type( \'product\', $args );
$args = array(
\'label\' => \'Product category\',
\'rewrite\' => array( \'slug\' => \'product_category\' ),
\'hierarchical\' => true,
);
register_taxonomy( \'product_category\', \'product\', $args );
}
add_action(\'init\', \'custom_post_types\', 0);