Home › Forums › General Issues › Query cpt then echo if relationship exists › Reply To: Query cpt then echo if relationship exists
You forgot to set the postdata in foreach loop.
Just add this after the foreach line: setup_postdata($addon);
Here is the doc: https://developer.wordpress.org/reference/functions/setup_postdata/
That will set the $addon as the main $post for every iteration in foreach loop.
As an alternative solution, you could also add the needed post_id in ACF’s get_field method like this:
get_field(‘add_ons_suites’, $addon->ID)
That will bring the acf field data for that specific post
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.