Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);

        if($wp_query->have_posts()){
            while($wp_query->have_posts()){
                $wp_query->the_post();

                if(isset($this->_options['post_before'])){
                    echo $this->_options['post_before'];
                }

                $this->_components->thumbnail($this->_options);

                $this->_components->title($this->_options);

                the_excerpt();

                if(isset($this->_options['post_after'])){
                    echo $this->_options['post_after'];
                }               
            }
            if($remove_nav != true){
                $this->_general_loop_nav($wp_query->max_num_pages);
            }
        }else{
            $this->_components->error_page($this->_options);
        }

        $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

1 Answer 1

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')
),

to

'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

 
discard

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.