Increasing the number of items on the search page

Hello,

Hopefully a quick question - is there a way to increase the number of items that appear on the page when someone uses the embedded X search function? How would I go about doing that?

Currently my site is only displaying 6 or so and I’d like to increase that to at least 10 if possible.

Thanks!

-Brent

Hi Brent,

Please add the following code under functions.php file locates in your child theme:

function search_filter($query) {
	if ( !is_admin() && $query->is_main_query() ) {
		if ($query->is_search) {
			$query->set('posts_per_page', 10);
		}
	}
}
add_action('pre_get_posts','search_filter');

Hope it helps :slight_smile:

Hey thai,

Is there really no other way to do this? I’ve avoided child themes up to this point because they’re a bit beyond my expertise to update with the changing versions…

If I change the number of blog posts on my main page would it also increase the number on the search page? If so, how do I do that?

Appreciate the assistance and suggest that this option be added in the future.

-Brent

Hi There,

You can try with this plugin instead: https://wordpress.org/plugins/custom-posts-per-page/.

Let us know how it goes!