Home › Forums › General Issues › Custom Post Type Relationship Archive Page › Reply To: Custom Post Type Relationship Archive Page
Sorry for the late reply:
When I put this code in my archive page for artists, it only outputs the field data for the latest post in that custom post type, rather than the one in the url.
Eg: Three artists in order:
Joe
James
Jack
If I’m on site.com/artists/jack it out puts the data for Joe.
<div class="container-fluid">
<?php // check if entries exists
if( have_posts() ):
// loop start
while( have_posts() ): the_post(); ?>
<?php
$posts = get_field('featured_works');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
<span>Custom field from $post: <?php echo $post->post_name; ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endwhile;
// reset query
wp_reset_postdata();
// end
endif; ?></div>
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.