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

  • 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

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 );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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