stefanosn
stefanosn

Reputation: 3324

Wordpress wp_query exclude word and category

I am trying to exclude word 'Vape' and exclude category using wp_query. Is it possible?

$args = array(

's' => '-Vape',
'cat' => '-62',
'posts_per_page'=>'16',
'paged'=>$paged,
'orderby' => 'date',
'order'   => 'DESC'
);

$wp_query = new WP_Query($args);

I use the code above but its not working. I don't get the items that have in their title the word 'Vape' which is right but i get the items of the category 62...any help appreciated!

Upvotes: 2

Views: 202

Answers (1)

David Alsbright
David Alsbright

Reputation: 1565

Try with category__not_in:

$args = array(

    's' => '-Vape',
    'category__not_in' => array( 62 ),
    'posts_per_page'=>'16',
    'paged'=>$paged,
    'orderby' => 'date',
    'order'   => 'DESC'
);

$wp_query = new WP_Query($args);

Edit: category__not_in expects an Array to be passed.

Upvotes: 3

Related Questions