我尝试使用id、slug、name,并将tax\\u查询作为一个数组,但它仍然会输出该帖子类型的所有帖子。
下面是我的自定义分类法“特定于事件”:
function theme_event_category(){
$labels = array(
\'name\' => \'Event Specifics\',
\'singular_name\'=> \'Specific\',
\'search_items\' => \'Search Event Specifics\',
\'all_items\' => \'All Event Specifics\',
\'parent_item\' => \'Parent Event Specific\',
\'parent_item_colon\' => \'Parent Colon:\',
\'edit_item\' => \'Edit Specific Item\',
\'update_item\' => \'Update Specific Item\',
\'add_new_item\' => \'Add New Event Specific\',
\'new_item_name\' => \'New Specific Item\',
\'menu_name\' => \'Event Specific\'
);
$args = array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'event\')
);
register_taxonomy(\'event_specific\', \'event\', $args );
}
add_action(\'init\', \'theme_event_category\');
这是我的查询,它应该只输出“特定于事件”分类法中的“主事件”标记:
$quertest = array(
\'post_type\' => \'event\',
\'posts_per_page\' => 1,
\'tax_query\' => array(array(\'event_specific\', \'slug\', \'main-event\')),
);
$upcoming_events = new WP_Query( $quertest );
<?php while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post();
echo \'Title: \';
the_title();
?>