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


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;                                 
                    'posts_per_page' => $total_posts,
                    'post__not_in' => array_merge($do_not_duplicate, $unwanted_post_ids ),
                    'paged' => $paged,
                    'tax_query' => 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?

  • 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
    Commented Dec 18, 2012 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
    Commented Dec 18, 2012 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. Commented Jun 15, 2013 at 6:28

5 Answers 5


Try to use the following:

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

Instead of using:

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

I had the same issue and it works for me.

  • 'page' is just used for a static front page. Otherwise 'paged' is needed.
    – JohnG
    Commented Aug 1, 2022 at 11:15

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:


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


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?


I had the same problem, although specifically paginating using AJAX. get_query_var('paged') returned an empty string, so $paged was always setting to "1", and - although the pages were changing - the pagination links always showed "1" as the current page.

To solve my issue, I just grabbed the page value passed through to my functions file ($_POST['page']) by AJAX, called it $pagination_no, then changed the $paged formula to:

$paged = ($pagination_no) ? $pagnination_no : 1;

That did the trick.


Use page, not paged, on 👉🏻static front page👈🏻

✅ The solution:

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

⭐️ A better syntax (see source):

$paged = get_query_var('page', 1);

🙋🏻 Inside the loop you can just use directly the global $page value (see docs):

global $page;

If you are on a static front page you have to use the page query variable instead of the paged one (see documentation).

The global $page always returns an integer.

🔍 A better approach:

$paged = 1;
if ( get_query_var('paged') ) $paged = get_query_var('paged');
if ( get_query_var('page') ) $paged = get_query_var('page');

This will gracefully fallback no matter where you use the code.

Here an old reference that tries to solve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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