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!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.