Home › Forums › ACF PRO › Call for posts on archive page if their relationship item is matching category › Reply To: Call for posts on archive page if their relationship item is matching category
if I understand the relationships:
CTP Recipes -> Relationship -> Ingredients
Ingredient -> Taxomomy -> Ingredient Type (ie vegetables)
on “vegetables” page you would need to do a query to get every ingredient post with the term (already done by WP, but you’d need to do it yourself to get the list of post IDs). Then you would need to use all of the posts returned from this query to get the recipe posts that have these ingredients.
Unfortunately, the query to get all of the recipes will likely grow out of hand and will very likely cause a time out on the DB query. Let’s say that you have 20 ingredients listed as veggies, then you’d be doing 20 “Like” queries in an ‘OR’ meta query which would be extremely bad.
My suggestion would be to set up a bidirectional relationship field (see https://www.advancedcustomfields.com/resources/bidirectional-relationships/ OR https://wordpress.org/plugins/post-2-post-for-acf/) between recipes and ingredients. With a bidirectional field you would not need to do any additional queries. You would simply loop over the ingredients and then get the recipe relationship.
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!