Hi @phoenixbelle1
The best way to hide posts or products on search results is to use pre_get_posts filter hook. Here is an example of the code that prevents protected regular posts from being displayed in search results:
add_action( 'pre_get_posts', function ( $query ) {
if ( ! is_admin() && $query->is_main_query() && 'blog' === $query->query['pagename'] ) {
$posts = get_posts(array('post_type' => 'post', 'post_status' => 'publish', 'numberposts' => -1));
if(empty($posts)) { return; }
$protected_posts = array();
foreach($posts as $post) {
if(!members_can_current_user_view_post($post->ID)) {
$protected_posts[] = $post->ID;
}
}
if(empty($protected_posts)) { return; }
$query->set( 'post__not_in', $protected_posts );
}
} );
We don’t have any code to hide products on search result, so you will need to modify it.
Best