Support

Account

Home Forums Front-end Issues Querying with ACF relationship values Reply To: Querying with ACF relationship values

  • Thank you again for taking the time to not only write me back but also clean up my code. I am still learning as I go (trying my best to improve) and appreciate being pointed in the right direction. The code you provided gets everything to display only if I remove the wp_reset_postdata(); from

      $this_post = $post->ID;
        $posts = get_field('doctor_specialties');
        if ($posts) {
          foreach ($posts as $post) {
            setup_postdata($post);
            ?>
              <h2 class="related-specialties-title">
                <a class="doctor-specialty-link" href="<?php 
                    the_permalink(); ?>">More <?php 
                    the_title(); ?> Specialists</a></h2>
            <?php 
          } // end foreach $posts
          //wp_reset_postdata();
        } // end if $posts

    If I keep the wp_reset_postdata then doctors with the same specialty do not display. I am still trying to figure out the best solution for doing the if else statement. The If else has to be outside of the div.tout-more-specialists, so whatever I am checking with the if statement must exist outside of the div itself. When I var_dump ($doctors) outside of the div.tout-more-specialists NULL is returned. This makes sense because I am not even calling the doctors array until later in the code. But if I var_dump ($doctors) inside the code after the doctors array I see the list of doctors that have the same specialties (example pediatrics has many doctors), and on the doctors single page that have no like specialties like (neurology), this is returned array(0) { } . So I know that I need to check to see if ($doctors) returns a full array, else display the other div. I am just trying to figure out how to write the if else statement outside of the div.tout-more-specialists. So far everything I have tried ends up breaking the code. Thank you again for your time John, you are extremely generous for all your help.