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.

Hey, I'm RJ! For more learnings about software and management, find me @rjzaworski or sign up for my semi-regular newsletter.

Let’s keep in touch

Send me timely updates on software, product, and process.