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(); ?>
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.