Show number of results on Wordpress search page

If you haven’t already read it, Michael Martin’s article on improving the wordpress search page is worth a quick glance. In return for a little fast and loose with global variables, we can improve performance while counting our search results. This works by foregoing a new WP_Query object in favor of simply hooking the existing global query:

<?php global $wp_query; echo $wp_query->post_count; ?> Results Found

I haven’t checked to see if WP_Query caches identical searches across instances, but this approach would at least save the overhead of instantiating a new query object.

Let’s keep in touch

Reach out on Twitter or subscribe for (very) occasional updates.

Hey, I'm RJ: digital entomologist and intermittent micropoet, writing from the beautiful Rose City.