Ready to get started?Download WordPress


Date and Time Picker Field
Posts not sorting by time field (2 posts)

  1. Sean M.
    Posted 9 months ago #

    Hi, I can't get posts to sort by the time field regardless of format used. I checked the values being saved to the DB, by enabling custom fields for the post type and verifying the value stored and they appear to be correct UNIX timestamps.

    What I'm experiencing is that the posts sort by numerical value (e.g. 12:00 PM comes after 6:00 PM) and despite trying even using a 'meta_query' alongside the typical 'orderby' with 'meta_key' and 'meta_value_num', I can't seem to get the posts to sort correctly. Not sure what I'm doing wrong. Here's an example of the query I'm running:

    <?php $args = array(
    	'post_type' => 'saturday_event',
    	'orderby' => 'meta_value_num',
    	'meta_key' => 'start_time',
    	'order' => 'ASC',
    	'nopaging' => true
    query_posts( $args );
    while ( have_posts() ) : the_post(); ?>

    Anybody know what might be wrong here? Thanks for your help!


  2. roflman79
    Posted 6 months ago #

    You need to check the option, save as UNIX timestamp.

    This should fix the ordering then.


You must log in to post.

About this Plugin

About this Topic