我已经为自定义帖子类型创建了一个自定义分类法,并为其创建了一个自定义页面。
问题是我只想显示属于该类别的自定义帖子,而不想显示子类别中的帖子。因此,我为循环编写了以下查询:
<?php global $wp_query;
$args = array_merge( $wp_query->query_vars, array( \'post_type\' => \'product\', \'include_children\' => \'false\' ) );
query_posts( $args );
if(have_posts()) : while(have_posts()) : the_post(); ?>
虽然
\'include_children\' => \'false\'
包含在
$args
它仍然显示子类别中的产品。我试着把它改成
\'post_parent\' => 0
, 同时使用它们,但没有任何效果。
以下是我的分类代码:
function productcat_taxonomy() {
$labels = array(
\'name\' => _x( \'Product Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Product Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Product Categories\' ),
\'all_items\' => __( \'All Product Categories\' ),
\'parent_item\' => __( \'Parent Product Category\' ),
\'parent_item_colon\' => __( \'Parent Product Category:\' ),
\'edit_item\' => __( \'Edit Product Category\' ),
\'update_item\' => __( \'Update Product Category\' ),
\'add_new_item\' => __( \'Add New Product Category\' ),
\'new_item_name\' => __( \'New Product Category Name\' ),
\'menu_name\' => __( \'Product Categories\' ),
);
register_taxonomy(\'product-category\',array(\'product\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'product-category\' ),
));
}
add_action( \'init\', \'productcat_taxonomy\', 0 );
我哪里出错了?