• I’m trying to set up a small gallery that will display photos with a certain tag. This is within The Loop and before the content is output from The Loop.

    Despite following the Multiple Loop instructions and patterns, the only way I could get it to work was by defining the global scope first for $id, $post, $pages, and $wp_query and then caching $wp_query. I then had to set $wp_query = $my_query. Only then would it output the_thumbnail() (that fx is in functions.php). Reversing the caching made the proper info available for the content output from The Loop (original).

    I’ve scoured the documentation for evidence I need to set the scope, but there doesn’t seem to be any. This setup is being run on a page, but must have access to all posts (to find the photos with the correct tag). I’ve left “showposts” in the query because that how I tested it in its last working state.

    <?php global $id, $post, $pages; ?>
         <?php  $my_id = $id;
                $my_post = $post;
                $my_pages = $pages; ?>
         <?php global $wp_query; ?>
    		<?php if(is_page()) { ?>
    		<?php $temp_query = $wp_query; ?>
    
    		<?php $my_query = new WP_Query('showposts=2'); ?>
    		<?php $wp_query = $my_query ?>
    
    <ul class="thumbnails">
    	<?php //if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    		<li id="post-<?php the_ID(); ?>">
    		<a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute(); ?>"> <?php the_thumbnail(); ?></a>
    		</li>
    	<?php endwhile; ?>
    		<?php endif;?>
    </ul>
    		<?php $wp_query = $temp_query; ?>
    		<?php } ?>
    	<p>does <?php //print_r($wp_query); ?> it print?</p>
    	</div>
    </div>

    Thanks so much for your help!

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

    (@gorgeousearth)

    After all that I forgot to post the actual question 🙂

    Am I doing something wrong here? This doesn’t seem like “The Right Thing” to do…

Viewing 1 replies (of 1 total)

The topic ‘global $wp_query required for nested loop?’ is closed to new replies.