Skip to main contentSkip to footer

A standard way to change the number of search results displayed is something like this:

$myquery = "&posts_per_page=5";
$myquery = $query_string.$myquery;
query_posts( $myquery );

Unfortunately, this breaks Relevanssi. Relevanssi hasn’t played nice with posts_per_page in any case, for some reason I don’t really understand — this is legacy code from the original wpSearch plugin.

However, from Premium version 1.4.4 and free 2.9.2, you can now adjust the search results per page in a fairly easy and clean manner. Add this to your site:

add_filter( 'post_limits', 'rlv_postsperpage' );
function rlv_postsperpage( $limits ) {
	if ( is_search() ) {
		global $wp_query;
		$wp_query->query_vars['posts_per_page'] = 10;
	}
	return $limits;
}

Adjust the value (10) the way you want.

Another way to do this:

add_filter( 'relevanssi_modify_wp_query', 'rlv_postsperpage' );
function rlv_postsperpage( $query ) {
    $query->query_vars['posts_per_page'] = 10;
    return $query;
}