Support » Themes and Templates » found_posts

  • Can someone please shed some light on the $wp_query->found_posts option. I did not find much on it. It seems to hold the result for all possible posts in a given query, even if the query has a limit on it.

    Example: If I have 10 posts and set showposts=2, it will display 2 but say it found 10.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Found posts is part of the WP_Query Object…

    As you said it simply holds the value of the total results..

    All you need to know should be here.

    Is there something in particular you need to know?

    Mostly just curious. I recently wrote my own pagination script which was obviously more then it needed to be. I found this property and it solved all my problems. On my index page I was limiting the number of posts shown to 5 (showposts=5), but I wanted, at the bottom with the pagination to display the total number of pages, like PAGE 1 OF 10. So I stored the query request

    $theQuery = $wp_query->request;

    Then I stripped the LIMIT from that request, as it was limiting to 5. Then re-ran the query without the limit for the sole purpose of getting the total number of posts based on my query. A lot of work and database stuff for nothing.

    I did not realize the wp_query object had that property stored.

    Plonk this in one of your template files…

    print '<pre>';
    print '</pre>';

    Will give you plenty of info about what’s stored in wp_query…

    That’s what i did before posting the link, was quicker to do as i already had the editor and local install open on my screen…


    I have a plugin which uses the following piece of code:

    $this->found_posts = (int)$wp_query->found_posts;

    But i want to exclude a category, how can i adjust that “$wp_query” thingy? It isn’t set in the plugin it’s self.

    The plugin is for “pagination”. And the problem is, the plugin sees more posts becuz i used the “posts system” to post “portfolio items” which are not shown in the weblog itself.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘found_posts’ is closed to new replies.