Home › Forums › Front-end Issues › Query multiple values in relationship field › Reply To: Query multiple values in relationship field
You need to use LIKE to match products with recipes and you need to add an array for each product you’re trying to match. Also, remember to put the ID inside parentheses (“”) otherwise you will match “12” with “123”.
// GET RECIPES THAT HAVE A RELATIONSHIP TO PRODUCTS ON THE CURRENT PAGE - manually
$recipes_manual_meta_query = array(
'post_type' => 'recipes',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'products_under_recipes',
'value' => '"' . $products[0]->ID . '"',
'compare' => 'LIKE'
),
array(
'key' => 'products_under_recipes',
'value' => '"' . $products[1]->ID . '"',
'compare' => 'LIKE'
)
)
);
This is the manual solution (without going over the array of products for page), to show you clearly what the meta_query should look like.
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.