Let me start saying that I know a 'tax_query' is faster than 'meta_query'.
It's always recommended to use taxonomies over custom meta when filtering by custom data is required, but here I found myself in this situation.
I'm creating a Real Estate application where I have this obvious post type 'property'. Each property is supposed to have X number of rooms and bathrooms.
Then in my app you can filter properties by range... for example: Show all properties that have from 3 to 18 rooms.
The custom field way would be to add a custom field, eg: 'rooms' and then do my query like:
$args = array( 'post_type' => 'property', 'meta_query' => array( 'key' => 'rooms', 'value' => array(3,18), 'type' => 'numeric', 'compare' => 'BETWEEN', ), ); $query = new WP_Query( $args );
The taxonomy way would be for example to create a custom taxonomy called 'property_rooms', then create the terms like '1', '2', '3', etc.. and do my query by term ID's like:
$args = array( 'post_type' => 'property', 'tax_query' => array( 'taxonomy' => 'property_rooms', 'terms' => array(3,4,5,6,7,8,9,10,11,12,13,14,15...etc) // Just pretend these are the corresponding term id's ) ); $query = new WP_Query( $args );
And here's the question: Does tax_query beats meta_query even in situations like this?
It may be relevant to mention that we could be talking about thousands of properties.
Keep in mind sorting by these fields is neither a requirement nor a consideration to trade the speed of the query.