Query between two meta keys

Update – it may be supported in a meta_query. I need more information – see below. You can’t do it using a meta_query, it’s not supported. Do you have data in meta_data fields? – WordPress queries will exclude posts where any of the orderby (or meta_query) fields is missing. WordPress adds a join condition to … Read more

Get result from meta_query() between two numbers

Multiple meta values can be compared with BETWEEN with an array value: ‘meta_query’ => array( array( ‘key’ => REALIA_PROPERTY_PREFIX .’attributes_area’, ‘value’ => array( $first_val, $second_val ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’, ), // inner array. ), // outer array. You can see this in Developer Doc.

meta_query sorting by 2 keys

OK, the final workaround would be to split query: $sfp_query_args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘sfp_post_category’, ‘terms’ => $cat_id_arr ) ), ‘meta_key’ => ‘is_sponsored’, ‘post_type’ => ‘sfpposts’, ‘post_status’ => ‘publish’, ‘showposts’ => (int)$per_page, ‘paged’ => $paged ); …and use “posts_orderby” filter to modify ORDER part: add_filter( ‘posts_orderby’, ‘sfp_modify_orderby’ ); function sfp_modify_orderby( $orderby … Read more

Meta query terribly slow

I’ve come across this problem and it seems MySQL doesn’t deal well with the multiple joins to the same table (wp_postmeta) and OR-ed WHERE that WP generates here. I dealt with it by rewriting the join and where as mentioned in the post you link to – here’s a version that should work in your … Read more

How to do a meta query using REST-API in WordPress 4.7+?

You can write your own REST handler for custom queries if you want. In your case, the query can done by doing so: // Register a REST route add_action( ‘rest_api_init’, function () { //Path to meta query route register_rest_route( ‘tchernitchenko/v2’, ‘/my_meta_query/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘custom_meta_query’ ) ); }); // Do the actual … Read more