On the WordPress search page I have a sidebar with all the terms associated with the post type the search has been performed on. Each of the terms have a checkbox next to them.
I want to be able to show the number of results that would be returned if I applied the term to the current set of results.
So, lets say I search all the posts for the word 'blog' and I get 100 results. I might have something like this in the sidebar...
[ ] Tech (50)
[ ] Sport (33)
[ ] Gaming (7)
[ ] Other (10)
The only thing I have got which will do this is to run a WQ_Query for each term with the same search terms originally searched along with the term applied to the search. I ask for a single result (which seems to speed things up) and then I echo $query->found_posts which gives me the total number of results.
This works fine, but it does mean I have to run a WP_Query for every single term which seems incredibly inefficient. Does anyone have a better approach which will achieve the same result?