I am trying to find a way to combine a meta_query and a term_query and i got confused with the research.
$sport = 'basket';
$args_p = array(
'posts_per_page' => 10,
'post_type' => 'user',
'no_found_rows' => true,
'post_status' => 'publish',
'meta_key' => 'user_overall_rating',
'tax_query' => array(
array(
'taxonomy' => 'restricted-sport',
'field' => 'slug',
'terms' => array($sport)
'operator' => 'NOT IN')
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$r = new WP_Query( apply_filters( 'widget_posts_args',$args_p ) );
if (r->have_posts()):...
So i want to filter and get the top 10 users that does not have '$sport' basket as restricted sport. There are post_types that have taxonomies 'basket' ,'soccer' etc so i expected to get 10 top from the rest sports, but i get an error :) PHP Fatal error: Uncaught Error: Call to a member function have_posts() on null in widget-5.php "r->have_posts()"
NOT IN
is extremely slow and very, very heavy on the database. It would be much faster to list every restricted sport except the one you don't want. Avoid parameters that exclude like the plague for performance reasons. Also you mention you get an error, but you never say what the error is, can you edit your Q to clarify what it was?