[Plugin: Relevanssi – A Better Search] Solved feature: easier selection of what to (not) search
-
In Relevanssi, you have to put not searcheable posts/pages as comma separated list to the relevanssi settings page. As i see, this is not good for few people here, for me neither as i do not want to give client access to relevanssi setings, but i want to allow him excluding pages from search.
So i have added him meta box with “Exclude from search” checkbox (this is out of scope of this thread, I recommend using “Custom fields” plugin) with search_exclude name
And then i make this simple function
add_filter('relevanssi_search_filters', 'mc_exclude_relevanssi'); function mc_exclude_relevanssi ($values_to_filter) { $atts = array( 'post_type' => 'any', 'meta_key' => 'search_exclude', 'meta_value' => 1, 'posts_per_page' => -1 ); $my_query = new WP_Query($atts); $myposts = $my_query->posts; if($myposts) { $values_to_filter['expost'] = explode(',',$values_to_filter['expost']); foreach ($myposts as $post) { $values_to_filter['expost'][] = $post->ID; } $values_to_filter['expost'] = implode(',',$values_to_filter['expost']); }; return $values_to_filter; }
I think it is self explainable – i search all posts with selected custom post meta value and then i add their ID’s to filter
you can modify it to your needs.
- The topic ‘[Plugin: Relevanssi – A Better Search] Solved feature: easier selection of what to (not) search’ is closed to new replies.