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

<table>

<tr>
<th>Aktivitet</th>
<th>Sted</th>
<th>Dato</th>
<th>kontaktperson</th>
</tr>


 <?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))); ?>

<tr>   
<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>
</tr>

<?php endwhile; ?>

</table>

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

2 Answers 2

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

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:

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

Source:

http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters

share|improve this answer
    
Thanks for keeping me updated! –  Tom Boersma May 7 '11 at 4:16
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.