Last active
February 13, 2017 12:54
-
-
Save jchristopher/df9e4536e0fab89a4b1d to your computer and use it in GitHub Desktop.
Integrate WP Hide Post and SearchWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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