Home › Forums › Front-end Issues › Post Object: Selection does not show up in Custom Post Type › Reply To: Post Object: Selection does not show up in Custom Post Type
@Jonathan: YOU. ARE. AWESOME.
Here’s the code I used outside the loop to generate the field output for anyone else who’s searching to solve the same problem.
<?php
$post_id = get_the_ID(); // if ACF is outside loop, use this to get post ID
$post_objects = get_field('banner_selection', $post_id); // use second parameter to get the fields from this post
echo $post_id // Optional: use this to check if the ID is correct for this post
?>
<?php if( $post_objects ): // if banner selection was made, show those ?>
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<?php get_template_part( 'banner','side' ); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; // end if banner selection was made ?>
To output selection fields for Post Object fieldtype in ACF.
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.