Support

Account

Home Forums General Issues Order ACF relationship by acf date field of posts? Reply To: Order ACF relationship by acf date field of posts?

  • I should mention what I am really trying to do here is have a way to display upcoming and past events separately for events that are assigned to a specific post. This seems to be working for me:

    <?php
    	$today = date( 'Ymd' );
    	$post_ids = get_field('seminars', false, false);
    
    	$posts = get_posts(array(
    		'post_type' => 'any',
    		'posts_per_page'	=> -1,
    		'post__in'	=> $post_ids,
    		'meta_key'       => 'event_date',
    		'meta_compare'   => '>=',
    		'meta_value'     => $today,
    	));
    
    	if( $posts ) {
    		?>
    		<ul>
    			<?php foreach( $posts as $post): ?>
    				<?php setup_postdata($post); ?>
    				<li class="line">
    					<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    					<?php the_excerpt(); ?>
    				</li>
    			<?php endforeach; ?>
    		</ul>
    		<?php wp_reset_postdata(); ?>
    		<?php } ?>