从wp查询中排除类别不起作用

时间:2020-04-23 作者:Muhammad Adnan Bashir

我用这个代码来排除一个类别,但它仍然显示展览中的所有帖子。

$posts = get_posts(array(
    \'post_type\' => \'exhibition\',
    \'taxonomy\' => \'categories_for_exhibitions\',
    \'field\' => \'slug\',
    \'terms\' => array(\'current\'),
    \'operator\' => \'NOT IN\',
));

1 个回复
SO网友:Muhammad Adnan Bashir

找到了答案,可以让其他人受益

$posts = get_posts(array(
    \'post_type\' => \'exhibition\',
    \'tax_query\' => array(
            array(
                \'taxonomy\' => \'categories_for_exhibitions\',
                \'field\'    => \'slug\',
                \'terms\'    => \'current\',
                operator => \'NOT IN\',
            ),
        )

));

相关推荐