Support

Account

Home Forums ACF PRO How to get related posts from post object field Reply To: How to get related posts from post object field

  • This is the closest I got to what I want, but it isn’t the proper way. I need to be able to enter any post per page. And, the current way depends on the artists. And BCS of it, post per page doesn’t work properly.

    <?php 
                    $relation = new WP_Query( array(
    		            'tax_query' => array( 
    							array(
    								'taxonomy' => 'continent',
    								'field'    => 'term_id',
    								'terms'    => 836,
    							)
    						), 
     						'post_type'         => 'artist',
    					'posts_per_page'	=>  -1 ,
    
    				) );
    
             
    				if( $relation->have_posts() ) : 
    
    				while ( $relation->have_posts() ) : $relation->the_post(); ?>	
    
    					<?php
    
    					$featured_posts = get_field('relation');
    
    					if( $featured_posts && is_array($featured_posts) ):
    					
    				
    					$new_featured_posts = get_posts( array(
    						  'post_type'        => 'event',
    			              'post__in' => $featured_posts,
    			              'posts_per_page' =>4,
    						  'order' => 'DESC',
    						  'orderby' => 'meta_value',
    						  'meta_key' => 'webinar_date',
    					) );
    					?>
     
    				    <ul>
    						<?php
    					    foreach($new_featured_posts as $post){
    					    	?>
    					    		<li>
    						             <?php the_title(); ?> 
    									<p>
    										<?php the_field( 'event_date' ); ?>
    									</p>
    						        </li>
    					    	<?php
    					    }
    			
    			         ?>
    				    </ul>				    
    					
    				    <?php 
    				    // Reset the global post object so that the rest of the page works correctly.
    				    wp_reset_postdata(); ?>
    
    				<?php endif; ?>
     
    			<?php endwhile;  ?>
     
    			<?php endif;  ?>