Svedr
Svedr

Reputation: 589

WordPress The Loop and WP Query throws an inifinite loop

Ok, I am having a very strange issue. Look at the code, it is quite self-explanatory. It throws an infinite loop, and I am not sure why.

<?php
    //Only display 3 posts in the loop
    $args = array(
        'posts_per_page' => '3',
    );

    frontpage_query = new WP_Query( $args );

    if ( $frontpage_query->have_posts() ) : while ( have_posts() ) : $frontpage_query->the_post(); ?>

        <?php get_template_part( 'parts/loop', 'frontpage-grid' ); ?>

    <?php endwhile; endif; ?>

Upvotes: 0

Views: 26

Answers (1)

Barmar
Barmar

Reputation: 780818

while (have_posts()) :

should be

while ($frontpage_query->have_posts()) :

Upvotes: 3

Related Questions