Limit search results to show x posts

Change amount of posts shown on the search page – set here to 20

/**
 * Snippet Name: Limit search results to show x posts
 * Snippet URL: https://www.wpcustoms.net/snippets/limit-search-results-to-show-x-posts/
 */
  function wpc_search_results_per_page( $query ) {
  global $wp_the_query;
  if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
  $query->set( 'wpc_set_search_results_per_page', 20 );
  }
  return $query;
}
add_action( 'pre_get_posts',  'wpc_search_results_per_page'  ); 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x