我有一个名为“portcat”的自定义帖子类型,我想从页面中排除一个portcat类别(“weather”-ID=\'5”)。我试过了\'category__not_in\' => array( 5 ) 但显然,这不适用于自定义帖子类型。我可以在下面的代码中添加什么来排除它?
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$args = array(
\'post_type\' => \'port\',
\'paged\' => $paged,
\'posts_per_page\' => get_theme_option("portfolio_work_count"),
);
if (isset($_GET[\'slug\'])) {
$args[\'tax_query\']=array(
array(
\'taxonomy\' => \'portcat\',
\'field\' => \'slug\',
\'terms\' => $_GET[\'slug\']
)
);
}
SO网友:Adam
请看一下这个例子;
$args = array(
\'post_type\' => \'post\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'movie_genre\',
\'field\' => \'slug\',
\'terms\' => array( \'action\', \'comedy\' )
),
array(
\'taxonomy\' => \'actor\',
\'field\' => \'id\',
\'terms\' => array( 103, 115, 206 ),
\'operator\' => \'NOT IN\' //you must set the operator to NOT IN
)
)
);
$query = new WP_Query( $args );
更多详细信息,请参见法典中的WP\\U查询;
http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters