Exclude admin from WP_Query Contributors

I realize now that you’re not talking about WP_Query but WP_User_Query. Looking at the documentation for WP_User_Query it says this about the who parameter: who (string) – Which users to query. Currently only ‘authors’ is supported. Default is all users. Instead you can use the role parameter and exclude certain users by ID like so: … Read more

WP_Query with Metavalue

I would recommand to add meta_query in array param, try this add_shortcode( ‘sc_count_brands’, ‘sc_count_brands_code’ ); function sc_count_brands_code($atts) { $values = shortcode_atts( array(‘category’ => ‘Horology’,), $atts ); $args = array( ‘post_type’ => ‘brands’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘br_category’, ‘value’ => esc_attr($values[‘category’]), ‘compare’ => ‘=’ ), ), ); $query = new WP_Query( … Read more

Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first

First of all, just to clarify, in a normal situation without the specific order requirements, and assuming you are doing this on pre_get_posts hook, you would just do as follows: add_action(‘pre_get_posts’, function ($query) { // only perform for a given query // do your checks and return early if (! $query->is_main_query() || ! $query->is_home()) { … Read more

WP_Query ordering numbers as letters

To evaluate a meta value as a number, use meta_value_num. Try: $args = array( “fields” => “ids”, “meta_key” => “jogador_oficial”, “meta_value” => true, “meta_query” => array( “relation” => “AND”, “query_one” => array( “key” => “quantidade_corretas” “orderby” => “meta_value_num”, “order” => “DESC” ), “query_two” => array( “key” => “tempo_total” “orderby” => “meta_value_num”, “order” => “ASC” ), … Read more

Formulate a url to show posts with both taxonomy terms

Looks like you can define the AND logical operator with the URL parameters, specifically adding the “+” between your terms like this: url?taxonomy=term1+term2 This will ensure that only posts containing all terms listed are returned. Example: https://example.com/blog?food=sauce+cheese [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => food [terms] => … Read more