This Documentation is for SearchWP Version 3

Integrate WP Hide Post and SearchWP

WP Hide Post is a plugin that allows you to (among other things) exclude posts from search results.

Screen Shot 2014-09-02 at 8.25.38 AM

You will need to tell SearchWP to utilize the data stored by this plugin and in turn exclude results as well. You can achieve this integration by adding the following to your theme’s functions.php:

* Integrate WP Hide Post and SearchWP
* @link
* @param $ids
* @param $engine
* @param $terms
* @return array Excluded post IDs
function wp_hide_posts_searchwp_exclude( $ids, $engine, $terms ) {
$args = array(
'post_type' => 'any',
'post_status' => 'any',
'nopaging' => true,
'fields' => 'ids',
'meta_query' => array(
'relation' => 'OR',
'key' => '_wplp_post_search',
'value' => true,
'key' => '_wplp_page_search',
'value' => true,
$wp_hide_posts_ids = get_posts( $args );
if ( ! empty( $wp_hide_posts_ids ) ) {
$ids = array_merge( $ids, $wp_hide_posts_ids );
$ids = array_map( 'absint', $ids );
$ids = array_unique( $ids );
return $ids;
add_filter( 'searchwp_exclude', 'wp_hide_posts_searchwp_exclude', 10, 3 );
view raw gistfile1.php hosted with ❤ by GitHub

WP Hide Post hides posts from search results by flagging them with a Custom Field called _wplp_post_search so we need to tell SearchWP to exclude any posts with that meta_key. We’ll do that by using SearchWP’s searchwp_exclude hook and WordPress’ get_posts function to retrieve the IDs of all the posts that have been excluded from search by WP Hide Post. We’ll then send those IDs back to SearchWP and as a result they will be excluded by SearchWP.

[wpforms id="3080"]