get_query_var('paged') is always 1? Paginating custom post type. (7 posts)

  1. Leo Blanchette
    Posted 2 years ago #

    I've been trying to paginate results on a custom post type. While the "paginate_links" function seems to work, get_query_var('paged') always returns a 1.

    What causes this? How can I solve it?

  2. Kurt
    Posted 2 years ago #


    Are you using a page template? If yes, change it to this:

    (get_query_var('page')) ? get_query_var('page') : 1;

    Note that it's page vs. paged.

    For reference: http://codex.wordpress.org/Function_Reference/get_query_var

    I was running a custom loop in a page template and it drove me nuts for several hours.

  3. Leo Blanchette
    Posted 2 years ago #

    Thank you Kurt, this has been getting me for more than a few hours to say the least!

    I changed "paged" to "page" and the loop still doesn't respond. Testing, though, if I turn the "1" to a "2" things do respond. So I've isolated the problem to something in the get_query_far function.

    Also, its worth noting that I'm not using this either in a page template or archive, but in a different area. Does that change the game at all?

    Thanks for your help!

  4. Leo Blanchette
    Posted 2 years ago #

    I might have gotten closer to the problem.


    print_r($_GET); returns empty array. So the URL rewriting isn't happening?

    This is being used on a special root-level script which is meant for other websites to dial in and get results. It includes wp-load.php. Perhaps this method is leaving out something crucial?

  5. Leo Blanchette
    Posted 2 years ago #

    small update -

    when I put up raw url variables like ?page=7 and skip get_url_var and just do $paged = ($_GET['paged']) everything works fine.

    Building for the long-term however I'm trying to avoid work-arounds.

  6. Kurt
    Posted 2 years ago #

    I found this which states that including wp-load.php does not parse the URL or run the query: http://stackoverflow.com/questions/13860577/wordpress-wp-load-php

    Otto says, don't include wp-load.php: http://ottopress.com/2010/dont-include-wp-load-please/ implying that the script is not written in the best manner.

  7. Leo Blanchette
    Posted 2 years ago #

    Thanks. I suspected that might have been a part of the problem.

Topic Closed

This topic has been closed to new replies.

About this Topic