Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active February 13, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/df9e4536e0fab89a4b1d to your computer and use it in GitHub Desktop.
Save jchristopher/df9e4536e0fab89a4b1d to your computer and use it in GitHub Desktop.
Integrate WP Hide Post and SearchWP
<?php
/**
* Integrate WP Hide Post and SearchWP
* @link https://searchwp.com/docs/kb/integrate-wp-hide-post-and-searchwp/
*
* @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',
array(
'key' => '_wplp_post_search',
'value' => true,
),
array(
'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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment