WordPress loop collapses HTML after 61st post

I’m running a WordPress WP_GeoQuery to pull posts within a custom post type by location with no problem. However, the loop breaks the rest of the HTML on the page including the sidebar & footer. I played around with the ‘posts_per_page’ option and it appears that WordPress dies after the 61st (random number I know) post.

I realise that it can be paginated which will fix the issue and I will do this, but curiosity has got the better of me and it’s bugging me not knowing why. I’ve had a search around Google but couldn’t find any answers.

Read More

So, I basically wanted to know if WordPress has a limit of 61 posts set somewhere or if I’m doing something really silly that is breaking it? Code below..

Thanks for any help in advance!

<?php // get location of user
    $url = "http://freegeoip.net/json/". $_SERVER['REMOTE_ADDR'] .'';
    $geo = json_decode(file_get_contents($url), true);

    // store lat and long of user location
    $Slat = $geo[latitude];
    $Slng = $geo[longitude];
?>

<?php $args = array(
    'post_type' => 'event',
    'latitude' => $Slat,
    'longitude' => $Slng,
    'author'=> $user_id,
    'posts_per_page' => 61
    )
?>


    <?php $the_query = new WP_GeoQuery( $args ); ?>

        <?php $plus = 0; ?>
        <?php foreach( $the_query->posts as $post ) : ?>

        <?php $postid = get_the_ID(); ?>

            <div class="event clearfix">

                <div class="event-image grid-1-4 no-padding">

                    <?php $images = get_field('images'); ?>
                        <img src="<?php echo $images[0][sizes][thumbnail]; ?>" alt="<?php the_title(); ?>" />

                </div>

                <div class="event-info grid-1-2">

                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <form action="/edit-event" method="POST">
                        <input type="hidden" value="<?php echo $postid; ?>" name="id" />
                        <input type="submit" class="edit-button" value="edit event" />
                    </form>

                </div>

                <div class="event-details grid-1-4 no-padding">

                    <div class="detail">Distance <?php echo round($post->distance, 1); ?> mi</div>
                    <div class="detail">Price: &pound;<?php the_field('adult'); ?></div>

                    <?php include('countdown.php'); ?>

                </div>



            </div>

            <?php $plus++; ?>

    <?php endforeach; ?>

Related posts

Leave a Reply

2 comments

  1. Look into your logs, what is error/Exception thrown after that issue? Have you looked into that 61th (And maybe 62th) post? How is pagination working when displaying that 61th post? Please provide more information.

  2. The fix below incase anyone else has the issue. Simply add an if statement around the field which might not have a value set.

    <div class="event-image grid-1-4 no-padding">
    
        <?php if( get_field('images') ) : ?> 
            <?php $images = get_field('images'); ?>
                <img src="<?php echo $images[0][sizes][thumbnail]; ?>" alt="<?php the_title(); ?>" />
        <?php endif; ?>
    
    </div>