wp_query sorting – one specific meta_key value at last and then sort by create date

If you’re using WordPress 4.2 or newer then you can do the following: $args = array( ‘post_type’ => ‘products’, ‘posts_per_page’ => 10, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘tools_clause’ => array( ‘key’ => ‘tools’, ‘compare’ => ‘EXISTS’, ), ‘create_date_clause’ => array( ‘key’ => ‘create_date’, ‘compare’ => ‘EXISTS’, ), ), ‘order_by’ => array( ‘create_date_clause’ => ‘ASC’, … Read more

Query 3 meta_key and orderby

The meta_query has to be an array of array to manage the relation between the meta queried. You can read more on the codex page about wp_query here In an other side, post_type, post_status, has nothing to do on your meta_query clause, they are already in the main arguments if the query.

Speed up WP_query with meta comparing dates

Can you upgrade your hosting? I’ve had a very similar query running on AWS that is fine with 1700 events and meta_query that also had location. Another option for you (if it’s always the same query i.e. today as your queried date) is to use transients to store the result. $events_arr = get_transient(‘events_running_today’); if (!$events_arr) … Read more