WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I wrote a rather - unattractive function - a while ago and I was re-factoring some code and I realized my query function doesn't work ... I recently made a post about how my tansient posts were not working and it all boiled down to the basics of the query not working.

Now yes, I do actually get a post object back, and yes I do manage to loop through it and display some content. How ever the paging isn't working, its the same set of posts regardless of page number your on.

So in reading that post I checked to make sure I am getting the max number of pages. and I am.

But as stated, no matter the page I am on the posts are the same. Does the same concepts applied in the answer to my other question apply here or ...

    protected function _query_post($query, $remove_nav = false){
        global $wp_query;
        $original = $wp_query;
        $wp_query = new WP_Query($query);


                    echo $this->_options['post_before'];




                    echo $this->_options['post_after'];
            if($remove_nav != true){

        $wp_query = $original;  

Keep in mind this function is planning to be re-factored.

This question has not already been answered as the query coming in looks like this:

'query' => array(
    'post_type' => 'post',
    'paged' => get_query_var('page') // Look i'm already paged
share|improve this question
possible duplicate of Pagination not working with custom loop – Chip Bennett Oct 3 '13 at 19:06
up vote 1 down vote accepted

You aren't preserving the paged query var in your query. You can accomplish this by making line 4:

$wp_query = new WP_Query($query . "&paged=" . $original->query_vars['paged']);

UPDATE: After the edit on the OP, the issue was that the paging variable, paged was in the query being sent to the function. But, there was a typo so that the page variable (which would have been false in this case) was actually being sent to the function.

Therefore, we corrected:

'query' => array(
  'post_type' => 'post',
  'paged' => get_query_var('page')


'query' => array(
  'post_type' => 'post',
  'paged' => get_query_var('paged')
share|improve this answer
So that kind of worked. The issue is now it sias no posts were found, the query coming in is just 'posts' – TheWebs Oct 3 '13 at 19:43
Also see updated OP - the query coming in is already paged. – TheWebs Oct 3 '13 at 19:54
the page query var would give a page id (or probably false in this case). You need to get the paged query var. – murdaugh Oct 3 '13 at 19:55
please see the updated OP I have already gotten that. – TheWebs Oct 3 '13 at 19:58
unless it's a typo, you have 'paged' => get_query_var('page') where it should read 'paged' => get_query_var('paged') – murdaugh Oct 3 '13 at 19:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.