Support

Account

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>