• When I run the code below, CFS no longer appears on the page when I run a get() function. It works perfectly when I run a get() function before the code below, but doesn’t appear after. Is there something wrong with this post query code?:

    <?php
    
    $counter = 1; //start counter
    $grids = 3; //Grids per row
    
    $args = array(
     	'posts_per_page'=> 1,
     	'ignore_sticky_posts' => 0
    );
    $query = new WP_Query($args);
    
    if($query->have_posts()) :  while($query->have_posts()) : $query->the_post(); ?>
    	//Do stuff
    	<?php $counter++;
    endwhile;
    endif;
    
    ?>

    When I comment out sections, it appears that the “while($query->have_posts()) : $query->the_post();” is causing the error. Any idea why this would be?

    • This topic was modified 6 years, 2 months ago by dougburnett.
    • This topic was modified 6 years, 2 months ago by dougburnett.
Viewing 1 replies (of 1 total)
  • Thread Starter dougburnett

    (@dougburnett)

    I found the solution. I didn’t realize I needed to reset the post query. The correct code is:
    `<?php

    $counter = 1; //start counter
    $grids = 3; //Grids per row

    $args = array(
    ‘posts_per_page’=> 1,
    ‘ignore_sticky_posts’ => 0
    );
    $query = new WP_Query($args);

    if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?>
    //Do stuff
    <?php $counter++; ?>
    <?php endwhile; endif; wp_reset_query(); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Post Query is Breaking CFS’ is closed to new replies.