I'm using Advanced Custom Fields to create a class schedule. I need to get the time field to sort correctly to display the class schedule in the correct order. Currently it is not, and I don't understand what I need to do to get it sorting correctly.

Here is the live link: http://studio34yoga.com/yoga-movement/class-schedule/ You can see on Monday that the classes are not in the correct order. "start_time" is my time picker field that I am hoping to sort on. What follows is an abridged version of my PHP code. Any help is appreciated.


$args = array( 'post_type' => 'Classes', 'posts_per_page' => 70, 'meta_key' => 'start_time', 'orderby' => 'meta_value_num', 'order'=>'ASC' );       
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

if(get_field('day') == "2monday") :

    echo '<div class="class"><span class="class-time">';
    echo get_field('start_time');
    echo '&nbsp;-&nbsp;';
    echo get_field('end_time');
    echo '</span></div>';




1 Answer 1


It looks like the times are being stored as plain text strings like "10:00 am - 12:00 pm" which will be pretty impossible to sort correctly during your wp_query call.

Try the date and timepicker add-on and it should allow you to store in a sortable format. You can use it for only times and not dates. Then if you need a time range, you can have "start_time" and "end_time" and then sort by "start_time".

  • THanks for your help on this... I will look closer at it. I thought I was using the date / time picker, as it gives me a time chooser interface -- It is not just a text field. Commented Jul 16, 2013 at 18:30
  • If you are using it, it should store in the database as a unix timestamp which is great for ordering... Let me know if you are using that, or if you are using a different add-on. Would curious to see why it is not working.
    – Jake
    Commented Jul 16, 2013 at 18:53
  • Thanks, Jake. I have the date / time field installed and activated, which I am assuming is what would be giving me the field. I have no other addons / plugins that I would be using. Everything I read on this seems to talk about ordering by date, and it's not as helpful for me to understand how to order by time. Commented Jul 16, 2013 at 19:38
  • I tried to test, but the date/time field doesn't work right for me... It saves a nice timestamp into the db, but it doesn't show in the metafield after. So all I can say is make sure that you have "Save as timestamp?" set to "Yes".
    – Jake
    Commented Jul 17, 2013 at 21:02
  • 1
    Thanks, Jake -- This resolved itself with the latest update to ACF and ACF date / time picker. You were so helpful for me to determine that it wasn't me but the plugin! :) Commented Aug 16, 2013 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.