Home › Forums › Front-end Issues › Query with 2 parameters and 2 meta_key › Reply To: Query with 2 parameters and 2 meta_key
You need to use nested meta queries https://make.wordpress.org/core/2014/10/20/update-on-query-improvements-in-4-1/
and your going to need to dynamically generate the meta query. As an example the cycle portion of it might look something like this
$meta_query = array('relation' => 'AND');
if ($cycle) {
$sub_query = array('relation' => 'OR');
$cycles = explode(',', $cycle);
foreach ($cycles as $cycle) {
$sub_query[] = array(
'key' => 'cycle',
'value' => '"'.$cycle.'"'
'compare' => 'LIKE'
);
} // end foreach cycle
$meta_query[] = $sub_query;
} // end if cycle
Please note that the above has not been tested and is meant only as an example.
A word of caution, too many LIKE and nested LIKE queries could time out the request.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.