Support

Account

Home Forums Front-end Issues Query to display all posts with ACF relationship value Reply To: Query to display all posts with ACF relationship value

  • Hello again Nataliette.

    With my previous solution, did you create a loop inside the if-statement for when you have company posts?

    
    <?php get_header(); ?>
    <?php // if is a link to Read More from company single related post
    if(isset($_GET['company'])){ ?>
    <?php
    $company_id = $_GET['company'];
    	Show all related posts from the company's singular page.
    $doctors = get_posts(array(
    							'post_type' => 'doctor',
    							'meta_query' => array(
    								array(
    									'key' => 'location', // name of custom field
    									'value' => '"' . $company_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)
    						));
     
    						?>
    						<?php if( $doctors ): ?>
    
    //ETC. This is not a full loop
    ?>
    <?php } else { ?>
    	<?php while ( have_posts() ) : the_post(); // The Loop ?>
                <?php get_template_part( 'content','excerpt' ); ?>
    	<?php endwhile; ?>
    <?php } ?>
    <?php get_footer(); ?>