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

I'm trying to list events (custom posttype 'kurs') by event date, which are stored as custom fields ('dato').

My loop so far looks like this:

<?php $loop = new WP_Query( array( 'post_type' => 'kurs' ) ); ?>

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<li><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?></li>

<?php endwhile; ?>

What I need is a list of post(event)-titles from today forward in the future...

share|improve this question
this has been asked like 345345325932845 times. simply store the date as a UNIX timestamp and use the orderby => 'meta_value_num' argument... – onetrickpony Jan 25 '11 at 14:21
up vote 1 down vote accepted

You need to use the meta_key to sort your events in your array. Like so:

<?php $loop = new WP_Query( array( 'post_type' => 'kurs', 'meta_key' => 'dato', 'order_by' => 'meta_value', 'order' => 'ASC' ) ); ?>
share|improve this answer
Cool, that works, thanks for the fast reply! Only one more thing: how to display just future events? – Tom Boersma Jan 25 '11 at 14:27
Do you mean that after the date is passed you want them to not be there anymore? The best way would be to use post expiration that sets a published event to "draft" or "trash". I use this plugin wordpress.org/extend/plugins/post-expirator . Also, since I did correctly answer your original question, mark it as correct so it shows up as answered. – eileencodes Jan 25 '11 at 14:32
This is what I mean, but I would like to use the already existing event date for this, otherwise I have to enter both event date and expiration date... – Tom Boersma Jan 25 '11 at 14:46
Not sure how to do that, I would post a new question. – eileencodes Jan 25 '11 at 14:48
ok, thanks so far! – Tom Boersma Jan 25 '11 at 14:51

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.