Forums › Forums › Search & Filter Pro › Display Search Results Count
Tagged: search results count
- This topic has 8 replies, 2 voices, and was last updated 9 years, 1 month ago by Ross.
-
Anonymous(Private) October 13, 2015 at 4:59 pm #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(Private) October 15, 2015 at 4:39 pm #27440Hi Vikki
Why do you have
$search = new WP_Query("s=$s & showposts=-1");
?This is not part of S&F
Thanks
Ross Moderator(Private) October 15, 2015 at 4:50 pm #27446Hi 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
Ross Moderator(Private) October 15, 2015 at 5:10 pm #27450Hi 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
Ross Moderator(Private) October 19, 2015 at 1:38 pm #27677Hi 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
-
AuthorPosts