WordPress.org

Ready to get started?Download WordPress

Forums

found_posts (5 posts)

  1. ckruse
    Member
    Posted 5 years ago #

    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.

  2. Mark / t31os
    Moderator
    Posted 5 years ago #

    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.
    http://codex.wordpress.org/Function_Reference/WP_Query

    Is there something in particular you need to know?

  3. ckruse
    Member
    Posted 5 years ago #

    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.

  4. Mark / t31os
    Moderator
    Posted 5 years ago #

    Plonk this in one of your template files...

    print '<pre>';
    print_r($wp_query);
    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...

  5. marissenruben
    Member
    Posted 4 years ago #

    *bump*

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.