0

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?

2 Answers 2

0

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

0
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.