Another wp_query question for yous... has anyone ever encountered a need for more than two items in a wp_query meta_query array? So you know that this is how you do it with two:
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
),
array(
'key' => 'price',
'value' => array( 20, 100 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
)
);
$query = new WP_Query( $args );
I have a scenario where I'd like to have a dynamic number of meta_queries in there... and, often, more than just two. I'll output my args array below so you can see the kind of info I'm wanting to search on. (And for why I'm using compare like that, you can see the explanation about querying ACF relationship fields
here, down by the "single-location.php" section).
Unless I'm not seeing it, I don't see the wp_query codex saying anything about a limit here... but I found that if I had more than three of these sales_rep_region arrays, the query failed. Three or less worked. Weird? It may be that I just need to build my own custom SQL query, which I can do, but I prefer to use wp_query if I can.
-----------
Array
(
[post_type] => sales-rep
[post_status] => publish
[posts_per_page] => -1
[orderby] => menu_order
[order] => ASC
[meta_query] => Array
(
[relation] => OR
[0] => Array
(
[key] => sales_rep_regions
[value] => "236"
[compare] => LIKE
)
[1] => Array
(
[key] => sales_rep_regions
[value] => "245"
[compare] => LIKE
)
[2] => Array
(
[key] => sales_rep_regions
[value] => "254"
[compare] => LIKE
)
[3] => Array
(
[key] => sales_rep_regions
[value] => "265"
[compare] => LIKE
)
[4] => Array
(
[key] => sales_rep_regions
[value] => "269"
[compare] => LIKE
)
)
)