• Resolved volfro

    (@volfro)


    Hey all,

    I’m trying to use a loop and query_posts to grab content from a certain page, then rewind_posts to display the rest of the content normally.

    It’s an extra section in my header.php:

    <?php if (have_posts()) : while (have_posts()) : the_post();
    	$values = get_post_custom_values("Page Description");
    endwhile; endif; ?>
    
    	<?php if ($values[0]) : echo $values[0];
    	else :
    		query_posts('pagename=default-description');
    		if (have_posts()) : while (have_posts()) : the_post();
    			the_content();
    		endwhile; endif;
    
    	endif; rewind_posts(); ?>

    But rewind_posts isn’t actually doing anything. The if statement works as expected, but if I’m on a page that doesn’t have anything in Page Description, it calls the default-description page where it’s supposed to AND for every other loop on the page.

    Why? I thought rewind_posts was supposed to reset the WP_query…

    Any help is greatly, greatly appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter volfro

    (@volfro)

    Leave it to the Codex. I’d thought I’d read The Loop section enough to make my eyes fall out, but I guess I didn’t read carefully enough.

    Created a custom query:

    <?php if (have_posts()) : while (have_posts()) : the_post();
    	$values = get_post_custom_values("Page Description");
    endwhile; endif; ?>
    
    	<?php if ($values[0]) : echo $values[0];
    	else :
    		$default_description = new WP_Query('pagename=default-description');
    		while ($default_description -> have_posts()) : $default_description -> the_post();
    			the_content();
    		endwhile;
    	endif; ?>

    …and did a rewind_posts() at the end of header.php.

    This solves my problem (I’m avoiding the use of plugins like Improved Include Page for this particular client), but I’m a little confused by the Codex’s description of why specifically query_posts, placed above the main loop, still affects the main loop, even after I do a rewind_posts. Any WP gurus care to explain?

    My PHP knowledge is limited to understanding of WP templates, so layman’s terms help here. Thanks again.

Viewing 1 replies (of 1 total)
  • The topic ‘rewind_posts after query_posts ?’ is closed to new replies.