Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.