I wrote an article some time ago highlighting ways to implement search improvements to WordPress (and the default search DOES suck). Now, I’d like to update you on where I am, including some further changes that I made last night.
My current set-up is that I’m displaying 3 posts per page. However, in the case of search results, I’m displaying 12 per page, as I display only an excerpt and restricted social sharing and other output. The idea, like the results from a search engine, is to find the post or page that you’re after and click on it for the full version.
By default,WordPress only allows one “posts per page” value. To achieve this, you’ll need to read my original post which shows you how to override the search results to show more. I still use the Results Count plugin as well, which displays how many search results were returned.
In addition, on all post and page types I use the WP Page Numbers plugin to allow users to easily scroll across multiple pages, rather than use the default WordPress “Next” and “Prev” buttons.
Finally, Search Meter is an excellent plugin for finding out what your visitors are searching for.
Modifying the Search Results
Last night I had a brain-wave. After performing a search myself, I had one result. Except it was the usual excerpt and I had to click on it to view the full version. But, if there’s only one, why do this? Indeed, if there’s 3 or less, why not display the full posts, and only collapse to the excerpt version if there’s more than this?
And that’s what I’ve changed – try it! Look for “wordpress“, for instance, and you’ll find pages of potential results, all displayed as limited excerpts. Look for “avforum” and one result will be returned and the entire post will be shown. Lovely.
To do this I simply compare the results of
get_option('posts_per_page'). I do this outside of “the loop”. The former will return the total number of posts being returned and the latter will return the number of posts per page that you’ve your WordPress to. In my case, this latter value is 3.
So, if a search is performed and 1 results is returned out of 3, my theme can make the decision to output the full version of the post instead of the smaller version. I can also make the decision at this point whether to override the number per page to 12 or not (if I’m display the excertp versions).
I hope this makes sense – please comment if you need any further clarity on this.