I have a dynamic form that brings the data from the URL and searches the DB with a wp_Query. It works great if I insert a dingle value manually. but if I pass the data from the URL I receive all the posts. even if I manually insert an array with multiple values it returns all posts.
here is the query:
the first part works great.
the second one cost_per_month_ipcenter_filter_new
is the one with the problem.
$args = array(
'posts_per_page' => -1,
'post_status' => 'publish',
's' => $_GET['s'],
'post_type' => 'ipcenters',
'meta_query' => array(
'relation ' => 'AND',
array(
'meta_key' => 'setupfee_ipcenter',
'meta_value' => $setupfee_ipcenter_val,
'meta_compare' => $setupfee_ipcenter_comp,
),
array(
'key' => 'cost_per_month_ipcenter_filter_new',
'value' => array('101-150', '0-50'),
'compare' => '=',
)
),
);
$the_query = new WP_Query( $args );
if I write
'value' => '101-150',
it works.
I tried 'value' => ['101-150', '0-50'],
This is the same as the written above but it still doesn't work.
this is how it appears in the url
cost_per_month_ipcenter_filter_new%5B%5D=0-50&cost_per_month_ipcenter_filter_new%5B%5D=101-150
the final result it to place the $_GET['cost_per_month_ipcenter_filter_new']
as the value array.
What am I doing wrong?
meta_query
arg) usekey
,value
andcompare
. I.e. Without themeta_
part. And'value' => '101-150'
works because the value is a string. So when it's an array of values,compare
should beIN
, i.e.'compare' => 'IN'
.IN
really fixed it