Documentation

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

Available since: 1.1

searchwp_include

View Parameters »

Use this filter to define the pool of potential results SearchWP can use when running searches.

Example: To directly limit searches to three specific posts, add the following to your active theme’s functions.php:

<?php
function my_searchwp_include_three_posts( $ids, $engine, $terms ) {
// make sure searches are limited to posts 134, 188, and 189
return array( 134, 188, 189 );
}
add_filter( 'searchwp_include', 'my_searchwp_include_three_posts', 10, 3 );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To limit search results to a single category, add the following to your active theme’s functions.php:

<?php
function searchwp_include_only_category( $ids, $engine, $terms ) {
// Limit to category 10
$categoryID = 10;
// Retrieve the IDs of all the posts in this category
$args = array(
'category' => $categoryID,
'fields' => 'ids',
'nopaging' => true,
);
$ids = get_posts( $args );
return empty( $ids ) ? array( 0 ) : $ids;
}
add_filter( 'searchwp_include', 'searchwp_include_only_category', 10, 3 );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To limit search results to posts written by a single author, add the following to your active theme’s functions.php:

<?php
function searchwp_include_only_author( $ids, $engine, $terms ) {
$authorID = 8; // limit to author 8
// get the IDs of all the posts in this category
$args = array(
'author' => $authorID,
'fields' => 'ids'
);
$posts = new WP_Query( $args );
return $posts->posts;
}
add_filter( 'searchwp_include', 'searchwp_include_only_author', 10, 3 );
view raw gistfile1.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$ids Array

The IDs SearchWP may have limited results to already. If $ids is NOT EMPTY: To retain optimal performance you should array_intersect() your limited IDs with $ids.

$engine String

The search engine being used

$terms Array

The submitted search terms

Fix Search on Your Site. No Coding Required!

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

Get SearchWP