I have a custom query in WordPress that is pulling a time assigned to a post item in a custom meta field. The times are entered in the following format:
1:00am, 2:00am, 1:00pm, 2:00pm, 3:00pm, etc
The query displays the posts in order of this time, however, its displaying them out of order, like this:
1:00am, 1:00pm, 2:00am, 2:00pm, 3:00am, 3:00pm, etc.
I need it to display them in the proper order, like this: 1:00am, 2:00am, 3:00am….11:00am, 12:00pm, 1:00pm, 2:00pm, 3:00pm, etc
I thought about simply switching to a 24 hour clock, but some users are not familiar with it.
Here is my query, can someone help me with a solution:
<ul>
<?php
$args=array(
'taxonomy' => 'day',
'term' => 'monday',
'post_type' => 'schedule',
'meta_key' => 'tr_show_time',
'orderby' => 'tr_show_time',
'order' => 'asc',
'posts_per_page' => 24,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $show_name = get_post_meta( get_the_ID(), 'tr_show_name', true ); ?>
<?php $show_time = get_post_meta( get_the_ID(), 'tr_show_time', true ); ?>
<li>
<?php echo $show_time;?> - <?php echo $show_name;?>
</li>
<?php endwhile; } wp_reset_query(); ?>
</ul>
I ended up using jQuery to solve this as, personally, I found it easier to do than in PHP.
I used this script and the following code:
http://benalman.com/projects/jquery-replacetext-plugin/