-
AuthorSearch Results
-
July 22, 2014 at 1:43 pm #2788
In reply to: How can I show the number of results?
RossKeymasterHey 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_postsor 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
July 21, 2014 at 2:54 pm #2728In reply to: How can I show the number of results?
AnonymousInactivefunction search_abovecontent() { ?> <div class="results"> <?php global $wp_query; $total_results = $wp_query->found_posts; ?></div> <?php } add_action('thematic_abovecontent','search_abovecontent',0);July 21, 2014 at 2:53 pm #2727In reply to: How can I show the number of results?
AnonymousInactiveHi 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 advanceJuly 8, 2014 at 1:35 pm #2258In reply to: How can I show the number of results?
RossKeymasterHey 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!
-
AuthorSearch Results