Home › Forums › General Issues › Sorting events with by Date Picker field › Reply To: Sorting events with by Date Picker field
Thanks! I ended up figuring it out through much trial and error and banging my head against the keyboard. Surprised it worked haha.
I also added a way to print the date in a more easily readable format. In case anyone else needs the code:
` <?php
// args
$args = array(
‘post_type’ => ‘events’,
‘posts_per_page’ => -1,
‘meta_key’ => ‘speaking_event_date’,
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘ASC’
);
// query
$wp_query = new WP_Query( $args );
// loop
while( $wp_query->have_posts() )
{
$wp_query->the_post();
$date = date_create(”.get_field(‘speaking_event_date’).”);
//echo get_post_meta($post->ID,’speaking_event_date’,true) . ‘<br />’;
echo ‘<li>’ . get_the_title() . ‘ – ‘ . date_format($date,’d F Y’) . ‘</li>’;
echo ‘<p>’ . get_the_content() . ‘</p>’;
}
?> `
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.