Support

Account

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>’;

    }

    ?> `