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 making a custom activity calendar for a client here: http://arbeidshesten.com/aktivitetskalender/

The backend is a custom post type "aktiviteter", with custom fields for the date ("dato") and some more details.

The code looks like this:



 <?php $loop = new WP_Query( array( 
'post_type' => 'aktiviteter', 
'meta_key' => 'dato',
'meta_value' => date('Y-m-d'),
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
 ) ); ?>

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

<?php $display_date = date('d.m.Y', strtotime(get_post_meta($post->ID, "dato", true))); ?>

<td><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?></td>
<td><?php echo get_post_meta($post->ID, "sted", true); ?></td>
<td><?php echo $display_date; ?></td>
<td><?php echo get_post_meta($post->ID, "kontaktperson", true); ?></td>

<?php endwhile; ?>


Funny thing is that the query returns just 2 aktivities, even though I entered (and published) about 5 future activities.

Anyone a clue?

share|improve this question
up vote 0 down vote accepted

I wonder if adding 'posts_per_page' => XXX to your query would give the desired results? Just a thought. Good luck!

share|improve this answer
This one helped, thanks! – Tom Boersma May 7 '11 at 4:14

My best guess is that if you are running WP 3.1, the meta_key, meta_value, and meta_compare parameters of the WP_Query is deprecated. In 3.1 and above, the meta_query parameter is what you should use. This is an awesome addition to WP_Query as it allows for query multiple meta values. Your query should look like:

    $loop = new WP_Query( 
            'post_type' => 'aktiviteter', 
                'meta_query' => array(
                    'key' => 'dato',
                    'value' => date('Y-m-d'),
                    'compare' => '>=',
                    'type' => 'DATE'
            'orderby' => 'dato',
            'order' => 'ASC'



share|improve this answer
Thanks for keeping me updated! – Tom Boersma May 7 '11 at 4:16

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.