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.

Putting this up after having hit a brick wall for possible solutions.

Have a site with quite a few custom post types and associated custom taxonomies. To help make things easy, I'm using a unified taxonomy.php template.

Within that template there are three loops. I would like all of them to run on the first page, after that, just the third loop. I understand how to make that work with is_paged() but there's a bigger problem that I just cannot resolve.

In my $args I included $paged from

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;     

But $paged always returns as 1, now matter what page I am on. If I do a straight

    get_query_var('paged')

Then nothing is returned, no matter if I am on the first, second, third or etc page.

I've read that you need to reset each loops for this to work, and that's a practice I've always followed.

I won't include the whole page here, as this is a rather long and complex taxonomy. Instead I'll show the base set up of the two loops.

NOTE: I can't use pre_get_posts for this page as it affects all loops. Each of these loops have separate posts_per_page requirements and other aspects that need to be kept separate.

At the top of the template I have

    //this present duplication
        $do_not_duplicate = array();

        global $wp_query;
        $term = $wp_query->queried_object;

And I set up my loop after my args with

while ($new_query->have_posts()) : $new_query->the_post();

The third loop that I want paged has this code nearby

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                                 
                $args=array(
                    'posts_per_page' => $total_posts,
                    'post__not_in' => array_merge($do_not_duplicate, $unwanted_post_ids ),
                    'paged' => $paged,
                    'tax_query' => array(
                            array(
                                'taxonomy'  => $term->taxonomy,
                                'field'     => 'slug',
                                'terms'     => $term->slug,
                                )
                            )
                    );

                // Re-run the query with the new arguments
                query_posts( $args );

I have been using wp_query rather than query_posts, but for my latest attempts that's what I've had there. Would prefer to change it back.

Any ideas?

share|improve this question
1  
can you post your code in its entirety? It's a tad hard to follow in prose with snippets, seeing the whole thing would make it a lot easier to grasp –  Tom J Nowell Dec 18 '12 at 12:43
    
also keep in mind that query_posts will use WP_Query at it's lowest level anyway, so there's no point in using it as a general query tool –  Tom J Nowell Dec 18 '12 at 12:43
    
Try using this: $paged = (get_query_var('page')) ? get_query_var('page') : 1; I am not sure about the reason for this but this worked for me once. –  Rohit Pande Jun 15 '13 at 6:28

2 Answers 2

Do you have the "paged" parameter in the URL of the page(s) that you are trying to use get_query_var with? As far as I know get_query_var("paged") is explicitly returning the value of the URL param so you need to have a URL like this for it to work:

/?paged=7

Alternatively you could read the URL param using straight-up PHP:

$_GET['paged']
share|improve this answer

You should be able to take this straight from the main $wp_query variable, you could do a print_r()and check for the various arguments you'd need, like paged, posts_per_page etc etc. What information can you see on your template when doing this?

share|improve this answer

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.