WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to filter WordPress search (and also WordPress listing of posts) on 2 values of a custom taxonomy.

I tried this code, filtering my custom taxonomy named "marque", excluding 70 or 67 IDs (nb : in my back-office, posts can only be classified into one term of my taxonomy a time) :

// Filtering on listing
function filtre_listes( $query ) {
    if ( !is_admin() ) {
        $query->set( 'marque', '-70,-67' );
    return $query;
add_action( 'pre_get_posts', 'filtre_listes' );

// Filtering on searches
function filtre_recherches(&$query)
    if ( $query->is_search && ( !is_admin() ) )
        $query->set('marque', '-70,-67');
    return $query;
add_action('parse_query', 'filtre_recherches');

But it doesn't seems to work. I use WordPress 3.0.5.

Any idea ?

Thanks a lot, and sorry for my approximative english !

share|improve this question


$tax_query = array(
    'relation' => 'AND',
        'taxonomy' => 'marque',
        'terms' => array( 70, 67 ),
        'field' => 'term_id',
        'operator' => 'NOT IN'
 //turn it into a WP_Tax_Query object...
$tax_query = new WP_TaxQuery($tax_query);

$query->set("tax_query", $tax_query);
share|improve this answer
Thank you a lot :) Have I some problems because of 3.0.5 version of Wordpress ? that's why I tried to use a classical syntax. Is "tax_query" filter not working only with 3.1+ versions of WP ? – Cédric G Aug 5 '11 at 15:52
De rien. (Mon francais et tres approximatif.) – Chris Carson Aug 5 '11 at 15:55
i'm loving your franglais. is this meant to be used with the pre_get_posts() function? it is giving me the error that the Class 'WP_TaxQuery' is not found – helgatheviking Feb 22 '12 at 3:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.