Note: You are viewing the documentation for Version 3View Version 4 Docs

Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP's many hooks, get support

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
Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP