Making the WordPress Search Better.
It sucks.
We all know it so why does this persist?
Perhaps a collaboration of developers and interested parties together on the WordPress search function needs to happen. I vote that Ryan Marganti get some credit for this little beauty from his blog. This allows you to set how many results show on a search page. It could of course be modified with the $query is_home or is_page for example to show a different number of posts on each of those layouts.
function change_wp_search_size($query) {
if ( $query->is_search ) // Make sure it is a search page
$query->query_vars['posts_per_page'] = 10; // Change 10 to the number of posts you would like to show
return $query; // Return our modified query variables
}
add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom function onto the request filter
Why is this not a built in function of WordPress? How handy would it be if where you selected your page template you chose how many excerpts you wanted to show on a particular one. I suppose it does mess with the WordPress > Reading settings but they have been around forever because it was brilliant foresight expanding on that is just evolution.
I digress. Relevanssi seems to be a great little plug-in. It worked out of the box has a ton of customizations and options and displayed beautiful results in my template. I haven’t delved into it much but I do hope that it is light-weight and intelligent enough to become a common replacement for the default WordPress search, which sucks by the way.
SPEAK / ADD YOUR COMMENT
Comments are moderated.
