admin管理员组

文章数量:1384639

Im using this code to exclude a category but it still show all posts in exhibition.

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

Im using this code to exclude a category but it still show all posts in exhibition.

$posts = get_posts(array(
    'post_type' => 'exhibition',
    'taxonomy' => 'categories_for_exhibitions',
    'field' => 'slug',
    'terms' => array('current'),
    'operator' => 'NOT IN',
));
Share Improve this question edited Apr 23, 2020 at 21:29 Muhammad Adnan Bashir asked Apr 23, 2020 at 19:05 Muhammad Adnan BashirMuhammad Adnan Bashir 93 bronze badges 1
  • Welcome to WordPress Development. I hope you find the answer(s) you are looking for. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Apr 23, 2020 at 19:52
Add a comment  | 

1 Answer 1

Reset to default 0

Found the answer so it can benefit someone else

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

));

本文标签: theme developmentExclude categories from wp query not working