Available since: 1.0
searchwp_posts_per_page
View Parameters »Many times you want a different number of posts per search results page. Further, you may want to customize that number per search engine. This filter allows you to customize how many results are returned for all search results pages.
Example: If you want to force 20 results per page for all supplemental search engines, add the following to your active theme’s functions.php
:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_searchwp_posts_per_page( $posts_per_page, $engine, $terms, $page ) | |
{ | |
if( $engine != 'default' ) { | |
// if this is a supplemental search engine, show 20 results per page | |
return 20; | |
} else { | |
// it's the default search engine, return whatever it was originally | |
return $posts_per_page; | |
} | |
} | |
add_filter( 'searchwp_posts_per_page', 'my_searchwp_posts_per_page', 30, 4 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$posts_per_page |
Integer |
The default number of posts per page |
$engine |
String |
The search engine in use |
$terms |
Array |
The search query |
$page |
Integer |
The page of search results being displayed |