Search Exclude
-
Plugin does not seems compatible with:
https://nl.wordpress.org/plugins/search-exclude/It seems to be returning everything I checked to not be found.
Can this be added?The page I need help with: [log in to see the link]
-
Seems you can add this to your query:
‘post__not_in’ => get_option( ‘sep_exclude’, array() )I added something to class-ysm-search
replaced in function search_posts
return $postsreplaced by
$posts = $wpdb->get_results($query, OBJECT_K); if ( class_exists( 'SearchExclude' ) ) { $search_exclude = get_option('sep_exclude', array()); foreach ($posts as $post) { if(!in_array($post->ID,$search_exclude)){ $filtered_posts[] = $post; } } return $filtered_posts; } else { return $posts; }Added plugin GROUPS support:
if ( class_exists( 'SearchExclude' ) ) { $search_exclude = get_option('sep_exclude', array()); foreach ($posts as $post) { if( class_exists( 'Groups_Cache')){ $product = new WC_Product( $post ); $visible_product = $product->is_visible(); } else { $visible_product = true; } if(!in_array($post->ID,$search_exclude) && $visible_product){ $filtered_posts[] = $post; } } return $filtered_posts; } else { return $posts; }-
This reply was modified 8 years, 7 months ago by
darkallman.
Hi!
Thanks for your time! I think it could be a nice feature for my plugin.
I’ll add it to my todo list.Stanislav
-
This reply was modified 8 years, 7 months ago by
YummyWP.
There is a small mistake in the code above….
Use this:$posts = $wpdb->get_results($query, OBJECT_K); if ( class_exists( 'SearchExclude' ) ) { $search_exclude = get_option('sep_exclude', array()); foreach ($posts as $post) { $visible_product = true; if( class_exists( 'Groups_Cache') && has_term('product', 'taxonomy', $post)){ $product = new WC_Product( $post ); $visible_product = $product->is_visible(); } else { $visible_product = true; } if(!in_array($post->ID,$search_exclude) && $visible_product){ $filtered_posts[] = $post; } } return $filtered_posts; } else { return $posts; }Above code is still not ok… still investigating a way to hide them from the search….
-
This reply was modified 8 years, 7 months ago by
darkallman.
Final version:
if(class_exists( 'Groups_Cache')){ foreach ($posts as $post) { if( has_term('product', 'taxonomy', $post) ) { $product = new WC_Product( $post ); $visible = intval($product->is_visible()); if($visible){ $visible = intval(Groups_Post_Access::user_can_read_post($post->ID)); } if($visible){ $filtered_posts[] = $post; } } else { $filtered_posts[] = $post; } } return $filtered_posts; } return $posts;Any news on implementing this?
Hi,
I’ll add this feature in next release (20th March).Regards
StanHi,
added Search Exclude compatibility in the latest release.
Unfortunately I don’t know what is ‘Groups_Cache’ class and why it needed, but you can add that code using a filter:
add_filter( 'smart_search_query_results', 'groups_cache_posts_filter' ); function groups_cache_posts_filter( $posts ) { if(class_exists( 'Groups_Cache')){ foreach ($posts as $post) { if( has_term('product', 'taxonomy', $post) ) { $product = new WC_Product( $post ); $visible = intval($product->is_visible()); if($visible){ $visible = intval(Groups_Post_Access::user_can_read_post($post->ID)); } if($visible){ $filtered_posts[] = $post; } } else { $filtered_posts[] = $post; } } return $filtered_posts; } }This is a class from the GROUPS plugin.
I have products that are only visible to users that are member of a group. These products must only be found if the user is a member.
https://nl.wordpress.org/plugins/groups/Got it.
So please use the above code if needed. -
This reply was modified 8 years, 7 months ago by
The topic ‘Search Exclude’ is closed to new replies.