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.6.10

searchwp_post_statuses

View Parameters »

Caution: this hook can expose content you do not want to show all visitors

Ensure your search results template properly restricts search results, as usage of this filter exposes content that would otherwise not be exposed, content you may not want to publicly display.

By default, SearchWP considers only content that has a post_status of ‘publish’, but you may want to change this (e.g. you run a membership site and want to include certain private posts in searches).

Example: To include both published and private content in ALL searches, add the following to your active theme’s functions.php:

<?php
function my_searchwp_post_statuses( $post_status, $engine ) {
$post_status = array( 'publish', 'private' );
return $post_status;
}
add_filter( 'searchwp_post_statuses', 'my_searchwp_post_statuses', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To include both published and private content in ONLY searches submitted to the my_supplemental_search supplemental search engine, add the following to your active theme’s functions.php:

<?php
function my_searchwp_post_statuses( $post_status, $engine ) {
$limited_post_status = array( 'publish' );
$additional_post_status = array( 'publish', 'private' );
if( is_null( $engine ) ) {
// this is the indexer running, so we want to index our additional content
$post_status = $additional_post_status;
} else {
// a search is taking place, but we only want to expose
// additional content if it's the my_supplemental_search search engine
if( 'my_supplemental_search' == $engine ) {
$post_status = $additional_post_status;
} else {
// this is a search that is NOT using the my_supplemental_search search engine
$post_status = $limited_post_status;
}
}
return $post_status;
}
add_filter( 'searchwp_post_statuses', 'my_searchwp_post_statuses', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

 

Parameters

Parameter Type Description
$post_status Array

Array of post statuses to consider

$engine String

null when indexer is running (you should return all potential post statuses) or the name of the search engine performing a search

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