Support

Account

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. ?>