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 can't figure out why this custom loop isn't displaying for me:. I've tried removing the if statement and removing certain query parameters but it just won't display. If I delete the loop entirely the page displays the layout, so I know it's the loop itself, I just can't find the problem.

Anyone with a sharp eye notice what I've done wrong?

    <?php /* Start the Loop */ ?>

<?php 
    query_posts(array( 
        'post_type' => 'events',
        'showposts' => 10 ,
        'meta_key' => 'event_datestart',
        'orderby' => 'meta_value' ,
        'order' => 'ASC' ,
    ) );  
?>
<?php while (have_posts()) : the_post(); ?>         
<?php 
    $raweventstart = get_field('event_datestart');
    $raweventend = get_field('event_dateend');

    $eventstart = strtotime("$raweventstart");
    $eventend = strtotime ("$raweventend");
    $now = strtotime("now"); 

    //Check if event is in the future or past.

    if ($eventstart >= $now) {
?>

                <div class="main-area-section-content">

                <div class="event-wrapper">
                        <div class="event-header">
                            <div class="event-date">
                            <?php echo $raweventstart; ?>
                            </div>
                            <div class="venue-name">
                            <?php if (get_field ('venue_name') ) { the_field('venue_name'); } ?>
                            </div>
                        </div>
                        <div class="event-content">
                            <div class="event-address">
                            <?php if (get_field ('venue_address') ) { the_field('venue_address'); } ?>
                            </div>
                            <div class="venue-phone">
                            <?php if (get_field ('venue_phone') ) { the_field('venue_phone'); } ?>
                            </div>
                            <div class="venue-website">
                            <?php if (get_field ('venue_website') ) { ?><a href="<?php echo get_field('venue_website'); } ?>">Venue Website</a> 
                            </div>
                            <div class="event-description">
                            <?php if (get_field ('event_description') ) { the_field('event_description'); } ?> 
                            </div>
                        </div>
                    </div>



                </div>
            <?php } //end check to see if event is in the past?>
<?php endwhile;?>
<?php wp_reset_query(); ?>  
share|improve this question
1  
I don't believe that get_field is a core function, is it? –  vancoder Apr 4 '13 at 16:57
    
@vancoder It's from ACF. As for finding out what's breaking it, try setting WP_DEBUG to true in your wp-config.php –  Lex R Apr 4 '13 at 17:00
1  
well first of all, one should never use query_posts. second, I suggest checking out WP_Query's meta_query to query for posts based on date, rather than filtering them after the query. –  Milo Apr 4 '13 at 17:03
    
Have you checked if $raweventstart is even populated in your loop? –  vancoder Apr 4 '13 at 17:11
    
Thanks @milo, you're right I shouldn't have been using query_posts. Below is this simplified verson that works using WP_query. Thanks all! –  Eckstein Apr 4 '13 at 19:52

1 Answer 1

This worked, thanks to advice from above (this is a simplified version):

    $args = array('post_type' => 'event');
    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
share|improve this answer

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.