Home › Forums › Front-end Issues › how to get sort post by date picker date › Reply To: how to get sort post by date picker date
Hi @pagol
You need to check out the orderby parameter of wp_query.
I haven’t tested this code and you might need to set the order parameter to either ASC or DESC as well. But give it a go:
<?php
$args = array(
'cat' => 'event',
'posts_per_page' => 2,
'orderby' => 'meta_value',
'meta_type' => 'DATE',
'meta_key' => 'fieldnameofdatepicker'
);
$news = new WP_Query($args);
?>
<?php while ($news->have_posts()) : $news->the_post(); ?>
<li>
<h3><?php the_field('date'); ?></h3>
<h4><?php the_title(); ?></h4>
</li>
<?php endwhile; ?>
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.