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.

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:

<ul>  
<?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; ?>
</ul>

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
add comment

1 Answer

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
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.