Home › Forums › Front-end Issues › Querying with ACF relationship values › Reply To: Querying with ACF relationship values
ANOTHER UPDATE
I was able to get the div to display alternate content with the if else however now the doctors that do have relationships don’t display. Instead the alternate div is always displayed.
<?php while ( have_posts() ) : the_post(); ?>
<?php $doctors = get_posts(array(
'post_type' => 'our-providers',
'orderby' => 'meta_value',
'post__not_in' => array($this_post),
'meta_query' => array(
array(
'key' => 'doctor_specialties', // name of custom field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
?>
<?php if( $doctors ): ?>
<div class="large-4 medium-4 small-12 columns tout-more-specialists" data-equalizer-watch="bridge">
<div class="single-specialty-container">
<?php
$this_post = $post->ID;
$posts = get_field('doctor_specialties');
if( $posts ): ?>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<a class="doctor-specialty-link" href="<?php the_permalink(); ?>"><h2 class="related-specialties-title">More <?php the_title(); ?> Specialists</h2></a>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<ul>
<?php foreach( $doctors as $doctor ): ?>
<li>
<a href="<?php echo get_permalink( $doctor->ID ); ?>">
<?php echo get_the_title( $doctor->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php else: ?>
<!-- If not providers with same specialty then display this div -->
<div class="large-4 medium-4 small-12 columns if-not-specialists" data-equalizer-watch="bridge">
<!-- No Related Providers Content Here -->
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php endwhile; // end of the loop. ?>
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.