Support

Account

Home Forums General Issues Trying to display posts related to other posts Reply To: Trying to display posts related to other posts

  • Oh, you’ll probably want to put the query for the attached posts inside the loop and pass the ID. Maybe something like:

    
    <?php 
    $loop = new WP_Query( array( 'post_type' => 'clients', 'posts_per_page' => 10 ) );
    ?>
    <?php if($loop->have_posts()) : ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="postbox-container postbox">
    <h3><?php the_title(); ?></h3>	
    
    <?php
    $ids = get_field('attach_to_client', $loop->ID);
    
    $query = new WP_Query(array(
    	'post_type'      	=> array('research', 'project_brief','persona','task_models', 'user_stories', 'style_guide'),
    	'posts_per_page'	=> -1,
    	'post__in'				=> $ids,
    	'post_status'			=> 'any',
      'orderby'       	=> 'modified',
    ));
    ?>
    
    <?php if ($query->have_posts()) : ?>
    <ul>
    <?php
    	while($query->have_posts()) :
    		$query->the_post();
    ?>
    	<li><?php the_title(); ?></li>
    
    <?php endwhile; ?>
    </ul>
    <?php else: ?>
    
          <p>Oops, there are no posts.</p>
    
    <?php endif; ?>
    </div>
    <?php endwhile; endif; wp_reset_query(); ?>