Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

question about wordpress WP_Query:

'post_type' => 'event_date' outputs dd/mm/yy ex: 31122012

I would like to order my frontend 'event_date' output not by latest WP post entry but by latest 'event_date'

Already tried 'order' => 'ASC' that sort only on WP post entry

Heres my code:

$arg = array('post_type' => 'livedates');
$the_query = new WP_Query($arg);
while($the_query->have_posts()) : $the_query->the_post();
$date = str_split(get_post_meta($post->ID, 'event_date', true), 2);

//the loop

endwhile;
share|improve this question
2  
Do you mean event date in a custom field? You'll need to store the date in reverse first of all. There are many questions on this site regarding sorting by meta data, I suggest doing a search. –  Milo Dec 31 '12 at 2:05
add comment

1 Answer

You can sort a query by a specified post meta field as a number or as a text field.
Example:

$query_args = array(
            'meta_key' => 'event_date',
            'orderby' => 'meta_value_num'
 );
 $event_query = new WP_Query( $query_args );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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