Support » Fixing WordPress » Why is max_num_pages empty?

  • When doing something like:

    global $wp_query;
    $total_pages = $wp_query->max_num_pages;
    var_dump($total_pages); exit;

    I get:


    when there are like 15, 16 posts. so it should go 1 -> 16

    I see other posts, that no one has responded to in regardes to this

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer


    On which theme template file are you doing this?


    At the bottom.

    If I do:


    I get a previous link for the post before the current one I am on.

    Moderator keesiemeijer


    The query on single.php returns a single post object that’s why the max_num_pages returns 0. What is it you want to do? Count all posts of the current post type?

    Maybe try wp_count_posts().


    No, pagination. I have already read the docs, but I only want it to show if there are more then one “page”


    I wanted it to show numbers. ONLY if there are more then one post or page.

    I figured out that to get this too work it has to go on the index.php template >.>

    How ever even with that fix it still doesn’t work, I have even looked at and copied how twenty eleven does it and still get nothing

    Moderator keesiemeijer


    You need to use next_posts_link() and previous_posts_link() on your index.php (extra “s” in the function name). If you want to have numbered pagination you could try the paginate_links() function or a plugin:

    This is loop in wordpress:
    $wp_query = new WP_Query();

    you can use $total_pages = $wp_query->max_num_pages;

    Other examples:
    $mypost=new WP_Query();
    <!– Show post –>

    Use $total_pages = $mypost->max_num_pages;

    Note: The bold line

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Why is max_num_pages empty?’ is closed to new replies.