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->ID . '"', 'compare' => 'LIKE' ), array( 'key' => 'products_under_recipes', 'value' => '"' . $products->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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.