Home › Forums › Front-end Issues › Querying with ACF relationship values › Reply To: Querying with ACF relationship values
Hey John, I ended up finding a solution. Thank you again for all your help. I really took a lot away from your suggestions and in the future will be developing and coding in a different way. THANK YOU.
Here is what worked, I know it may not be the cleanest.
<?php get_header(); ?>
<div class="row" data-equalizer="bridge">
<?php
// moved while outside of two main divs
while (have_posts()) {
the_post();
?>
<div class="large-4 medium-4 small-12 columns tout-single-doctor" data-equalizer-watch="bridge">
<div class="single-doctor-container">
<h2 class="doctor-title"><?php echo get_the_title(); ?></h2>
<?php
$posts = get_field('doctor_specialties');
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
?>
<a class="doctor-specialty-link" href="<?php
the_permalink(); ?>"><?php the_title(); ?></a>
<?php
} // end foreach $posts
wp_reset_postdata();
} // end if $posts
the_post_thumbnail('full');
$posts = get_field('doctor_services');
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
?>
<p>
<span class="doctor-background-title">Provider Services:</span>
<a class="doctor-specialty-link" href="<?php
the_permalink(); ?>"><?php the_title(); ?></a>
</p>
<?php
} // end foreach $posts
wp_reset_postdata();
} // end if $posts
// cleaned this up a bit to reduce code
// all of the get_field() calls
// need to be in The Loop
$fields = array(
'doctor_biography' => 'Provider Biography',
'doctor_education' => 'Provider Education',
'doctor_residency' => 'Provider Residency',
'doctor_internship' => 'Provider Internship',
'doctor_fellowship' => 'Provider Fellowship',
'doctor_board_status' => 'Board Status'
);
foreach ($fields as $field => $label) {
$value = get_field($field);
if ($value) {
?>
<p>
<span class="doctor-background-title"><?php
echo $label; ?>:</span>
<?php echo $value; ?>
</p>
<?php
} // end if $value
} // end foreach $fields
?>
</div><!-- end single-doctor-container -->
</div> <!-- end tout-single-doctor -->
<?php
$hasRelatedContent = false;
$this_post = $post->ID;
$posts = get_field('doctor_specialties');
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
} // end foreach $posts
// wp_reset_postdata();
} // end if $posts
$args = 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'
)
)
);
$doctors = get_posts($args);
if ($doctors) {
$hasRelatedContent = true;
}
if($hasRelatedContent == true) {
wp_reset_postdata();
?>
<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) {
foreach ($posts as $post) {
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
} // end foreach $posts
// wp_reset_postdata();
} // end if $posts
$args = 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'
)
)
);
$doctors = get_posts($args);
if ($doctors) {
?>
<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
} // end foreach $doctors
?>
</ul>
<?php
} // end if $doctors
wp_reset_postdata();
?>
</div><!-- end single-specialty-container -->
</div><!-- end tout-more-specialists -->
<?php
} // end if has content check
else {
?>
<div class="large-4 medium-4 small-12 columns tout-bridge-patient-portal_home">
<!-- Patient Portal Widget -->
<?php get_template_part( 'partials/global-custom-fields/patient', 'portal' ); ?>
</div>
<?php
}
?>
<?php
} // end while have_posts
?>
<div class="large-4 medium-4 small-12 columns tout-bridge-make-reservations_home" data-equalizer-watch="bridge">
<!-- Make Reservations Widget -->
<?php get_template_part ('partials/global-custom-fields/make', 'reservations'); ?>
</div>
</div>
<?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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.