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 } ?>
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.