Question

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

Was it helpful?

Solution

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' ) ); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top