WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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

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

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

Your Answer


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.