Support

Account

Home Forums General Issues Display pages on cpt posts which are related via repeater subfield – not working

Unread

Display pages on cpt posts which are related via repeater subfield – not working

  • I have a custom post type „Actors“. And I have pages, which I use for movies.

    On the pages I have a repeater field, which I use to display the actors who act in the movies. The name of the repeater field is filmcast. In the sub field (relationship field) filmcast-person I grab the CPT “Actors” posts. So the movie pages and the CPT “Actors” posts are related via the repeater sub field/relationship field.

    Example: On the movie page “Stagecoach” (title of the page) I grab the CPT post “John Wayne” (title of the post) in the repeater subfield (relationship field) filmcast-person to display John Wayne as one of the actors. This works perfectly.

    Now on the CPT “Actors” post “John Wayne” I want to display all movies/pages (with title and thumbnail in a list ordered by date) in which he acts/which are related to him. This should work for all actors automatically by using the title ID of each actor post.

    I tried to do that, following this forum posts: https://support.advancedcustomfields.com/forums/topic/show-custom-field-results-from-one-post-type-in-template-of-another/

    But it does not work. The CPT “Actor” posts are broken now and show nothing. I guess a messed it up.

    Any help would be very much appreciated.

    Here’s my code:

    
    <?php $i = 0; ?>
    
    <?php 
    
    $posts = get_posts(array(
    	'post_type'		=> 'page',
    	'posts_per_page'	=> -1,
    	'meta_key'		=> 'filmcast-person',
    	'meta_value' => get_the_ID(), 
    	'orderby'		=> 'date',
    	'order'			=> 'DESC'
    ));
    
    ?>
    
    <?php if($i == 0) { echo '<div class="ci-filmcast-row">'; } ?>
        
    <?php if( $posts ): ?>
    	
    	<ul>
    		
    	<?php foreach( $posts as $post ): setup_postdata( $post ); ?>
    		
            <div class="ci-image">
    		<?php the_post_thumbnail ( array (120, 140));  ?>
            </div>
                
            <div class="ci-title"> 
            <a href="<?php echo get_permalink($post->ID); ?>">
    		<?php echo the_title($post->ID); ?></a>
            </div>
    	
    	<?php endforeach; ?>
    	
    	</ul>
    
    	<?php wp_reset_postdata(); ?>
    
    <?php $i++; if($i == 5) { 	$i = 0; 	echo '</div>'; } ?>     
    <?php if($i > 0) { 	echo '</div>'; } ?>
    
    <?php endif; ?>
    
    
Viewing 1 post (of 1 total)

The topic ‘Display pages on cpt posts which are related via repeater subfield – not working’ is closed to new replies.