开发者

Select all posts which do NOT have a certain tag

In WordPress, how can I select all posts in a certain category (custom开发者_开发知识库 taxonomy), which do NOT have a certain tag (custom taxonomy).

The following code select all posts in a certain category (custom taxonomy), which DO have a certain tag (custom taxonomy). How does this have to be modified?

$postquery = new WP_Query( array( 
    'post_type' => 'myposttype', 
    'mycategory' => $cat, 
    'posts_per_page' => $numposts, 
    'orderby' => 'date', 
    'tax_query' => array( array(
        'taxonomy' => 'mytag',
        'field' => 'slug',
        'terms' => array('select by this tag', 'and this tag', 'and this tag'),
        ) )
    )
);

(I assume it would be better to just list all allowed tags, but that's not really feasible in my case, because new tags are still added.)


add 'operator'=>'NOT IN' to the 'tax_query' array

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜