Home › Forums › Front-end Issues › Query multiple values in relationship field › Reply To: Query multiple values in relationship field
Now it’s just a matter of php-array trickery to generate this query from array.
// GET RECIPES THAT HAVE A RELATIONSHIP TO PRODUCTS ON THE CURRENT PAGE - dynamically
$recipes_dynamic_meta_query = array(
'post_type' => 'recipes',
'meta_query' => array(
'relation' => 'OR'
)
);
foreach($product_ids as $product_id) {
array_push($recipes_dynamic_meta_query['meta_query'], array(
'key' => 'products_under_recipes',
'value' => '"' . $product_id . '"',
'compare' => 'LIKE'
));
}
Run this string trough get_posts and you’re set!
$recipes_manual = get_posts($recipes_dynamic_meta_query);
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.