wordpress meta_query datetime acf ordering code example
Example 1: wp query sort by meta date
$args = array(
'numberposts' => 2,
'meta_query' => array(
array(
'key' => 'event_date',
'value' => date("Y-m-d"),
'type' => 'DATE',
'compare' => '>='
)
)
);
$the_query = new WP_Query( $args );
Example 2: acf wordpress loop through and display blog posts order by date and type
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post'
));
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>