If you want to change the number of search results per page, you can use the following snippet:
add_action( 'pre_get_posts', 'wpkb_change_number_of_search_results_per_page' );
function wpkb_change_number_of_search_results_per_page( $query ) {
if ( is_search() && $query->is_main_query() ) {
$query->set( 'posts_per_page', 100);
}
return $query;
}
If you want to avoid problems in the backend, add !is_admin() &&
to the if condition.
Important notice: You have to add this snippet to the functions.php
file of your theme. If you add it so a special template file like search.php
, it is ‘too late’ and the default limit is already applied.