Available since: 1.0.8
searchwp_results
View Parameters »If you would like to examine or modify the array of results returned by SearchWP before they make it back to the theme template file you can use this hook. Depending on whether you have chosen to load post objects the passed array will consist either of post IDs or post objects.
To filter the array of search results returned by SearchWP, add something like the following to your 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_results( $results, $attributes ) { | |
// available $attributes are: | |
// | |
// $attributes['terms'] the search terms | |
// $attributes['page'] the current page | |
// $attributes['order'] the results order | |
// $attributes['foundPosts'] the number of found posts | |
// $attributes['maxNumPages'] the total number of pages of results | |
// $attributes['engine'] the engine in use | |
// modify $results in any way you'd like | |
return $results; | |
} | |
add_filter( 'searchwp_results', 'my_searchwp_results', 10, 2 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$results |
Array |
post objects (or IDs) |
$attributes |
Array |
Attributes of the search
|