post_limits
/**
* Limit the main query search results to 25.
*
* We only want to filter the limit on the front end of the site, so we use
* is_admin() to check that we aren\'t on the admin side.
*
* We also only want to filter the main query, so we check that this is it
* with $query->is_main_query().
*
* Finally, we only want to change the limit for searches, so we check that
* this query is a search with $query->is_search().
*
* @see http://codex.wordpress.org/Plugin_API/Filter_Reference/post_limits
*
* @param string $limit The \'LIMIT\' clause for the query.
* @param object $query The current query object.
*
* @return string The filtered LIMIT.
*/
function wpcodex_filter_main_search_post_limits( $limit, $query ) {
if ( ! is_admin() && $query->is_main_query() && ($query->is_search() || $query->is_home()) ){
return \'LIMIT 0, 25\';
}
return $limit;
}
add_filter( \'post_limits\', \'wpcodex_filter_main_search_post_limits\', 10, 2 );