SearchWP

This Documentation is for SearchWP Version 3

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:

<?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 );
view raw gistfile1.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$results Array

post objects (or IDs)

$attributes Array

Attributes of the search

  • $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
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]
[wpforms id="3080"]