Search Results for 'found_posts'

Forums › Forums › Search › Search Results for 'found_posts'

Viewing 5 results – 201 through 205 (of 205 total)
  • Author
    Search Results
  • #3050

    Ross
    Keymaster

    Hey Charley

    In your template you can add something like:

    global $wp_query;
    $total_results = $wp_query->found_posts;
    if($total_results==0)
    {
        _e('Sorry, no posts matched your criteria.');
    }

    There are other examples in here:
    http://codex.wordpress.org/The_Loop

    #2788

    Ross
    Keymaster

    Hey Mark

    It seems that maybe there is some other custom query on your page which makes this count incorrect – for example if your theme runs its own query_posts or something similar on the page then the found_posts value may be reflecting this.

    You could try resetting the main query before you check found_posts however this may break something else in your page:

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Something like:

    <?php
    wp_reset_query();
    global $wp_query;
    $total_results = $wp_query->found_posts;
    ?>

    Basically it seems like your theme is overriding the default setting, or not resetting the main query once it has finished running its custom functions?

    Thanks

    #2728

    Anonymous
    Inactive
    function search_abovecontent() {
    ?>
    <div class="results">		<?php
    global $wp_query;
    $total_results = $wp_query->found_posts;
    ?></div>
    <?php }
    add_action('thematic_abovecontent','search_abovecontent',0);
    #2727

    Anonymous
    Inactive

    Hi Ross this does not seem to have worked for me. I am using Thematic as my theme and added a hook to put this above the content

    <div class="results">		<?php
    global $wp_query;
    $total_results = $wp_query->found_posts;
    ?></div>

    Any thoughts how I can implement it?
    Thanks in advance

    #2258

    Ross
    Keymaster

    Hey Luca

    Try this in your template:

    <?php
    global $wp_query;
    $total_results = $wp_query->found_posts;
    ?>

    (Taken from: http://codex.wordpress.org/Creating_a_Search_Page)

    Let me know if that works!

Viewing 5 results – 201 through 205 (of 205 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.