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 only want to show upcoming events posts on the homepage. i have made a custom field using the 'custom field suite' plugin, called 'ENDS' representing the date an event ends.

as you can tell, i simply want upcoming events on the home, with the nearest to present date being first in line. upon expiring, i want it filed in the 'archive', which is visible on another page (which should also order archived event posts beginning with most recently expired event).

the template uses infinite scroll to load posts, and this is my index file, with the default loop: http://pastebin.com/x3NzZBZX

i need to integrate something like this, but have had no success:

<?php
$query = new WP_Query(
    'post_type' => 'post',
    'orderby' => 'meta_value',
    'meta_key' => 'ENDS',
    'order' => 'ASC',
    'posts_per_page' => -1,
    'meta_query' => array(
        'key' => 'ENDS',
        'value' => date('Y-m-d H:i:s'), // now
        'compare' => '>='
    ),
);
?>

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

<a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
</a>

<?php endwhile; ?>
share|improve this question

1 Answer 1

I believe the meta_query part should be a nested array, so your query should be like this:

$query = new WP_Query(
    'post_type' => 'post',
    'orderby' => 'meta_value',
    'meta_key' => 'ENDS',
    'order' => 'ASC',
    'posts_per_page' => -1,
    'meta_query' => array(
        array (
            'key' => 'ENDS',
            'value' => date('Y-m-d H:i:s'), // now
            'compare' => '>=',
            'type' => 'DATETIME',
        ),
    ),
);

Note that I also added the 'type' => 'DATETIME' to the meta_query inner array.

Hope this helps.

share|improve this answer
    
thanks! i am also struggling in replacing the default loop in the index file. very limited php skills. –  vulgarbulgar Oct 3 '12 at 19:39

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.