Forums › Forums › Search & Filter Pro › How can I show the number of results?
- This topic has 6 replies, 3 voices, and was last updated 10 years, 4 months ago by Ross.
-
Ross Moderator(Private) July 8, 2014 at 1:35 pm #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(Private) July 21, 2014 at 2:53 pm #2727Hi 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 advanceRoss Moderator(Private) July 22, 2014 at 1:43 pm #2788Hey 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
-
AuthorPosts