Forums Forums Search & Filter Pro How can I show the number of results?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #2255

    Can I show the number of results ? How?

    thanx in advance.

    Ross Moderator
    #2258

    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!

    Anonymous
    #2274

    Yeah, works!

    thanx a lot.

    Ross Moderator
    #2282

    🙂

    Anonymous
    #2727

    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

    Anonymous
    #2728
    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);
    Ross Moderator
    #2788

    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

Viewing 7 posts - 1 through 7 (of 7 total)