In my POSTS page (regular post type), I have setup a ACF relationship field. Inside this I can select company name which are all under the post type of directory_listings.
Now, I have the following code on the directory listings page, and therefore using simply get_field does not work because those values are not on this page, they are elsewhere on the POST type instead.
So unsure how to grab the information.
Code on one of the pages which is under the DIRECTORY_LISTINGS post type:
$posts = get_field('related_articles');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Example diagram as I am not great with explaining via text.
Currently I have setup the relationship field on the company edit page (directory_listing) instead. It works when doing the following: 1) Related Posts to this business listing -> select a post -> publish - > now displays the list on the business listing page. Example here: http://bit.ly/1vwydDl (bottom of the page)
2) I'd like from the POST edit page select a business which posts will appear on. I can put the field there via ACF no problem but getting it to actually display the results I cannot figure out.
get_field
in your foreach, you need to pass the $post->ID with it. I guess that's what you mean, right? - SBD<?php foreach( $posts as $post): $some_field = get_field('field_name', $post->ID); ?>
Something like that should work. - SBD