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 !