Perhaps this
function
will help you out.
Add tofunctions.php
after you made a backup of this file.
There is no need to add any in a template by using this function.
/**
* Set max output results for search page
*
* @param $queryVars
* @return results
*
* Read more @link https://developer.wordpress.org/reference/classes/requests /request/
* Tested with @version 5.3.2
*
*/
add_filter( 'request', 'search_results_pro_page' );
function search_results_pro_page( $queryVars )
{
// Prevent access to back-end
if ( is_admin() ) {
return;
}
// Set only on search
if ( isset( $_REQUEST['s'] ) ) {
// Adjust number of results shown
$queryVars['posts_per_page'] = 4;
}
// Return amount search results
return $queryVars;
}