Hello,
I’ve made a filter with different CPT posts that put there ID’s in an array and through ajax im trying to filter the content with a key value. But i can’t get it to work.. no clue what to do here.
So I’ve filterd post ID 807 and 222. And I have an array(807,222).
$programCat = array(807,222);
//Check if array is filled.
if($programCat){
$metaFilter = array('relation' => 'AND');
$filter = array(
'key' => 'zorgverlener_programmas',
'value' => $programCat,
'compare' => 'LIKE'
);
array_push($metaFilter, $filter);
}
$args = array(
'post_type' => 'cpt_zorgverleners',
'posts_per_page' => -1,
'tax_query' => $taxFilter,
'meta_query' => $metaFilter
);
key zorgverlener_programmas is a ACF relationship field. Im trying to display every post that has a value in the relationship field of “807 or 222”
How can this be done? Please help, cant find anything 🙁
Got it! need to foreach the $filter array 🙁
if($programCat){
// meta filter
$metaFilter = array('relation' => 'OR');
foreach ($programCat as $program){
$filter = array(
'key' => 'zorgverlener_programmas',
'value' => '"'.$program.'"',
'compare' => 'LIKE'
);
array_push($metaFilter, $filter);
}
}
is there a nicer way to do this?