sort events based on event date custom field

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:

Read More
<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…

Related posts

Leave a Reply

1 comment

  1. 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' ) ); ?>