[How to] Change Number of Posts Displayed on Search Only
WordPress usually use a constant number of posts for all your category pages, index, and also search results pages. For search pages, 10 posts are not usually enough.
To change this behavior, a simple query filter will do the trick.
If you want to change the number of posts displayed on the search results page, just put this code snippet to your functions.php
file:
function shailan_change_post_count( $query ) { global $wp_the_query; if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) { $query->set( 'posts_per_page', 20 ); // For search pages } elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) { $query->set( 'posts_per_page', 20 ); // For archives like tags, category, etc.. } return $query; } add_action( 'pre_get_posts', 'shailan_change_post_count' );
Don’t forget to change the number of posts (posts_per_page) in the snippet.
(Image credit)