Display Search Results Count

Forums › Forums › Search & Filter Pro › Display Search Results Count

Viewing 9 posts – 1 through 9 (of 9 total)
  • Anonymous
    #27233

    Hi Ross

    I would like to display the number of posts that are returned from a search. I have used the below code but it doesn’t work (it outputs “6” every time).

    Could you help?

    <?php
    $search_count = 0;
    $search = new WP_Query("s=$s & showposts=-1");
    if($search->have_posts()) : while($search->have_posts()) : $search->the_post();
    $search_count++;
    endwhile; endif; ?>
    
    Your search returned <?php echo $search_count; ?> results.

    Thank you

    Ross Moderator
    #27440

    Hi Vikki

    Why do you have $search = new WP_Query("s=$s & showposts=-1");?

    This is not part of S&F

    Thanks

    Anonymous
    #27443

    Hi Ross

    I googled how to do it and that was the code I found.

    🙁

    Ross Moderator
    #27446

    Hi Vikki

    Ok so S&F creates its own queries – what you are doing above is creating your own custom query – which S&F has not control over.

    Can you tell me which display method you are using for your results? (in the “display results” tab)?

    Thnaks

    Anonymous
    #27447

    Hi Ross

    I am using “custom template” and “load results using ajax”.

    Ross Moderator
    #27450

    Hi Vikki

    So first, you need to know where you can place the code for S&F – check the docs on customising your results:

    http://www.designsandcode.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    Once you have done that and are comfortable updating things in the results template let me know and I can provide you with the line of code to add to the template file you create.

    Thanks

    Anonymous
    #27451

    Hi Ross

    Thanks I have copied results.php into my new search-filter folder as requested. Please can I have the code?

    Thanks
    Vikki

    Anonymous
    #27675

    Hi Ross

    Could you provide me with the line of code I need?

    Thank you
    Vikki

    Ross Moderator
    #27677

    Hi Vikki

    I got slightly confused, but if you are using the results.php template provided (but copied in your theme folder) you will notice the line:

    Found <?php echo $query->found_posts; ?> Results<br />

    So this is already being displayed in your results – the variable you need is $query->found_posts

    Thanks

Viewing 9 posts – 1 through 9 (of 9 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.