【问题标题】:Select all posts which do NOT have a certain tag选择所有没有特定标签的帖子
【发布时间】:2011-08-05 18:56:19
【问题描述】:

在 WordPress 中,如何选择某个类别(自定义分类)中没有特定标签(自定义分类)的所有帖子。

以下代码选择特定类别(自定义分类)中的所有帖子,这些帖子确实具有特定标签(自定义分类)。这要怎么修改?

$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'),
        ) )
    )
);

(我认为最好只列出所有允许的标签,但在我的情况下这并不可行,因为仍然添加了新标签。)

【问题讨论】:

    标签: wordpress tags taxonomy


    【解决方案1】:

    'operator'=>'NOT IN' 添加到'tax_query' 数组中

    【讨论】:

    • 谢谢,没想到这么简单。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    相关资源
    最近更新 更多