Title: My second loop doesn&#8217;t work
Last modified: August 18, 2016

---

# My second loop doesn’t work

 *  Resolved [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/)
 * Hi there!
 * I created a template for a page (wp static page) with two loops. The first loop
   will show the last post of the blog. The second loop will show the content of
   the page.
 * The first loop code goes like this;
 * <?php query_posts(‘posts_per_page=1’); ?>
    <?php if (have_posts()) : ?> <?php
   while (have_posts()) : the_post(); ?>
 * <div…
 * <?php the_content()
    <?php endwhile; ?>
 * –> so far so good, it works! but then I insert the second loop and it doesn’t
   work. I must be missing anything;
 * <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class=”
   post” id=”post-<?php the_ID(); ?>”> <h2><?php the_title(); ?></h2> <div class
   =”entrytext”> <?php the_content(‘<p class=”serif”>read »’); ?>
 * <?php link_pages(‘**Paginas:** ‘, ”, ‘number’); ?>
 * </div>
    </div> <?php endwhile; endif; ?> <?php edit_post_link(‘Edit.’, ”, ”);?
   >
 * –> What I’m doing wrong? I have read I need to re-set the second loop but not
   sure how to do it?
 * Please, help!

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/my-second-loop-doesnt-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/my-second-loop-doesnt-work/page/2/?output_format=md)

 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-269955)
 * up!
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-269962)
 * Might consider the `rewind_posts()`
 * See this for other possible solutions:
    [The_Loop#Multiple_Loops](http://codex.wordpress.org/The_Loop#Multiple_Loops)
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-269981)
 * Hi MichaelH;
 * Thank you for answering.
 * I tried before, but rewind_posts() recovers the first post of the blog again 
   and I want the content of the wp static page.
 * I have to set the second loop so it recovers the content of that particular id
   page.
 *  [TechGnome](https://wordpress.org/support/users/techgnome/)
 * (@techgnome)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-269983)
 * Take a look at [Loop Example 1](http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1)……
   
   The part that maybe of the most use starts off with “If you need to keep the 
   original query around, you can create a new query object.”
 * -tg
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-269986)
 * Hi TechGnome;
 * I tried this one;
 * <?php $my_query = new WP_Query(); ?>
 * but it didn’t work. I need to query a page and I don’t know which is the call;
 * First loop -> calls first post in the blog (working)
 * Second loop-> calls content of page_id=5 (not working)
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270032)
 * up
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270033)
 * Will add this for your consideration:
 * [Template_Tags/query_posts#Retrieve_a_Particular_Page](http://codex.wordpress.org/Template_Tags/query_posts#Retrieve_a_Particular_Page)
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270034)
 * Instead of the second loop you could use thsi plugin:
    [http://guff.szub.net/2005/01/27/get-a-post/](http://guff.szub.net/2005/01/27/get-a-post/)(
   if it is for only one particular Page/post)
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270037)
 * Thanks MichaelH and moshu again;
 * This one;
 * <?php
    query_posts(‘page_id=7’); ?>
 * worked in my computer … but not in the host on the internet, odd thing.
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270038)
 * I checked the page id
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270049)
 * Do I miss anything in this code?
 * <?php
    query_posts(‘page_id=7’); ?>
 * Now it is not working
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270050)
 * get-a-post didn’t work either
 *  [nearlythere](https://wordpress.org/support/users/nearlythere/)
 * (@nearlythere)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270051)
 * ganzua, i’m trying help expand the codex page for query_posts; this would be 
   a good thing to add if you figure out a solution. (you can edit the codex too,
   if you like).
 * but i can’t read your code, so i can’t figure out how to help. do you know how
   to insert code into your posts? you need to use ‘backticks’ around each line.(
   see the message under the “send post” button below)…
 * at any rate, the thing you’re searching for is referred to as “multiple loops”,
   this may help in your searching.
 * I don’t really understand the inner workings of the issue, but I keep coming 
   across it, there are recommendations to “Try resetting the query to the default
   after using your custom queries.”
 * I saw this on the codex:
 * `<?php $temp_query = $wp_query; ?>`
 * `<?php query_posts('category_name=special_cat&showposts=10'); ?>`
 * `<?php while (have_posts()) : the_post(); ?>`
    `<!-- Do special_cat stuff... --
   >` `<?php endwhile; ?>`
 * `<?php $wp_query = $temp_query; ?>`
 * try that for each of your query loops, and tell us how it comes along!
 *  Thread Starter [ganzua](https://wordpress.org/support/users/ganzua/)
 * (@ganzua)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270052)
 * Hey nearlythere! Thanks for your response.
 * I was trying to solve this issue before uploading my site. I just can’t find 
   out a solution.
 * You can read my code now here; [http://90plan.ovh.net/~covenmys/wordpress/?page_id=3](http://90plan.ovh.net/~covenmys/wordpress/?page_id=3)
 * (web is in spanish since I live in Spain, sorry)
 * If you go through the code you’ll find some text dummie there which is the page
   content, but it doesn’t appear in the browser.
 * Besides, on bottom of the page there is an iclude fetching last phpbb posts and
   links are missreaded, I think by the server’s fault because in my own Apache 
   installation they work fine.
 * It might be an .htaccess of the server causing all this problems, I don’t know.
 *  [clarke1866](https://wordpress.org/support/users/clarke1866/)
 * (@clarke1866)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/#post-270055)
 * Your code is not viewable on that page. Copy the php code to a text file, and
   post a link to that. Thats what I would do.

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/my-second-loop-doesnt-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/my-second-loop-doesnt-work/page/2/?output_format=md)

The topic ‘My second loop doesn’t work’ is closed to new replies.

## Tags

 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Installing WordPress](https://wordpress.org/support/forum/installation/)
 * 21 replies
 * 6 participants
 * Last reply from: [nearlythere](https://wordpress.org/support/users/nearlythere/)
 * Last activity: [20 years, 7 months ago](https://wordpress.org/support/topic/my-second-loop-doesnt-work/page/2/#post-270110)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
