Title: dcoa's Replies | WordPress.org

---

# dcoa

  [  ](https://wordpress.org/support/users/dcoa/)

 *   [Profile](https://wordpress.org/support/users/dcoa/)
 *   [Topics Started](https://wordpress.org/support/users/dcoa/topics/)
 *   [Replies Created](https://wordpress.org/support/users/dcoa/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/dcoa/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/dcoa/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/dcoa/engagements/)
 *   [Favorites](https://wordpress.org/support/users/dcoa/favorites/)

 Search replies:

## Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/page/2/#post-2218954)
 * Thanks again guys, I actually didn’t get a chance to look at the last two posts
   above mine, were posted while I was writing my ‘Ok Fixed!’ anyone with the same
   problem as me might want to try those as well, but I am punching out, been trying
   to fix this for way too long.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/page/2/#post-2218951)
 * Ok Fixed!
    The problem was that `get_query_var('paged')` doesn’t seem to work
   when a page template is used on a static page on the homepage, So you have to
   use `get_query_var('page')` instead, but for some reason having this being called
   after the `$temp = $wp_query;` value was redefined meant it didn’t return a value.
   So I just had to move it up so it was called before the custom value was defined.
   Working code for anyone with the same problem is:
 *     ```
       <?php
        $paged = (get_query_var('page')) ? get_query_var('page') : 1;
       $temp = $wp_query;
       $wp_query= null;
       $wp_query = new WP_Query();
   
       $wp_query->query('posts_per_page=5&cat=4&paged='.$paged);
       while ($wp_query->have_posts()) : $wp_query->the_post();
       ?>
       ```
   
 * Then:
    `<?php endwhile; ?>` after the post.` Then: `<?php $wp_query = null; $
   wp_query = $temp;?>` at the end.
 * Full page code <a href=”[http://pastebin.com/N0dEngEf”>here</a&gt](http://pastebin.com/N0dEngEf”>here</a&gt);
 * This `<?php print_r ($wp_query->query_vars); ?>` was very useful in working out
   which variable was returning which value.
 * Thanks keesiemeijer for your patience and help.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218944)
 * Sorry, still not working, I forgot I changed that back from the code you gave
   me, but just tried it with `$wp_query->query('posts_per_page=5&cat=4&paged='.
   $paged);` back in and still the same problem.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218940)
 * Thanks, I did try with that in there but took it back out because it didn’t work,
   just put it back in to be sure and unfortunately still nothing.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218934)
 * I have tried removing everything in lines 13-28, to see if they were causing 
   a problem, but that didn’t fix it.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218933)
 * [Here you go.](http://pastebin.com/5gx1Nr4Y)
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218921)
 * I do have a bit of code that keeps the static page information at the top of 
   the posts. I tried your suggestion as well as completely deleting the extra code,
   just leaving the bare bones of the loop and unfortunately it is still not working.
   Could it be something not on this page that is failing? Sorry to be such a trouble,
   I really do appreciate your help.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218895)
 * It is a static front page, I tried that code but unfortunately still nothing.
   I tried echoing the various values on the page and
 * `get_query_var('page')` returns nothing, no value
 * `get_query_var('paged')` returns “1” on both the first and second page.
 * $paged returns 1 as well.
 * Would this mean that the code is right but something is amiss elsewhere?
 * also, If I change the else statement to
    `else { $paged = 2; }` It then loads
   only second page, and wont go back to the first, does this meant that the if 
   and elseif statements aren’t being satisfied?
 * thanks for your help so far
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218877)
 * Additionally, If I echo $paged, It prints as “1” both on the first and second
   page, so that must be what the problem is. (Not sure if there is a better way
   to check that? like a trace statement or something?
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [query_posts() Pagination – tried all fixes, still can't work it out.](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/)
 *  Thread Starter [dcoa](https://wordpress.org/support/users/dcoa/)
 * (@dcoa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-pagination-tried-all-fixes-still-cant-work-it-out/#post-2218876)
 * Hi, Thanks for the reply, unfortunately still no luck, implemented your code 
   as such:
 *     ```
       <?php
       $temp = $wp_query;
       $wp_query= null;
       $wp_query = new WP_Query();
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $wp_query->query("posts_per_page=5&cat=4&paged=".$paged);
       while ($wp_query->have_posts()) : $wp_query->the_post();
       ?>
       ```
   
 * But no change to the problem, still the same thing on first and second page.

Viewing 10 replies - 1 through 10 (of 10 total)