So I have a custom post type called “Events”. In each event, i have a custom field called “start_time_date” which returns a date like “08/01/12”. How would i sort these posts to return the posts so that the posts are sorted by the start_time_date in an ascending order (start_time_dates closer to current date gets shown first).
Here’s my current code:
<? query_posts("cat=$currentID&showposts=100"); ?>
<? if ( have_posts() ) : ?>
<? while ( have_posts() ) : the_post(); if (time() < strtotime(get('end_time_date'))) :?>
<? $originalDate = get('start_time_date'); $newDate = date("M j, Y", strtotime($originalDate)); ?>
<div class="post">Some Post Data</div>
<? endif; endwhile; ?>
<? endif; ?>
Did you try something like:
I am not sure what exactly
dateis in the database columns but it’s something like that. Also, the order might need to but changed but I don’t think it matters.Edit
I did some more research and
&orderby=date&order=ascis correct for the date and ordering.Sorry about that, did you read through Displaying Posts Using a Custom Select Query in the WordPress codex?
They also added
query_posts('&meta_key=popularity&orderby=meta_value');wheremeta_keyis the name of your custom field.Found here: Class Reference/WP Query