WordPress.org

Forums

Relevanssi - A Better Search
Solved feature: easier selection of what to (not) search (2 posts)

  1. thomask
    Member
    Posted 2 years ago #

    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.

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    This highly useful feature comes built-in in the Premium version of Relevanssi. That one works a bit better though, as Relevanssi doesn't even spend time indexing the posts that are hidden.

    So, a clever idea, but one I'm keeping as a Premium feature, so if you want it in the free version, this is a good way to do it. Premium license is fairly cheap, though, and comes with other goodies...

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic