Posted on

Disabling Relevanssi

If you need to disable Relevanssi, for example for a particular template, all you need to do is to unhook two filters:

remove_filter( 'posts_request', 'relevanssi_prevent_default_request' ); 
remove_filter( 'posts_pre_query', 'relevanssi_query', 99 );

Before versions 4.10.2 (free) and 2.12.2 (Premium), you need to unhook these filters:

remove_filter( 'posts_request', 'relevanssi_prevent_default_request' ); 
remove_filter( 'the_posts', 'relevanssi_query', 99 );

15 comments Disabling Relevanssi

      1. Thank you, but how can I achieve/run it? Do I have to add the code to the template (PHP file) of the plugin? If so, that’s not what I want. It would change the plugin on all sites. I just want to use it on one page. I tried some conditional tags (https://codex.wordpress.org/Conditional_Tags) for functions.php, but unfortunately I could not bring it to work.
        I also tried a plugin (https://wordpress.org/plugins/insert-php-code-snippet/) to insert your codes into a page, but it also didn’t work.
        Sorry, I’m not a programmer :/

        1. In that case I recommend you hire a programmer. You need to edit your theme (or build a plugin for it), not the Relevanssi plugin files. Disabling on just one page is a bit tricky (and I do wonder what you’re trying to achieve; this isn’t necessarily the right way to do it), but a skilled WP developer should be able to handle it.

          1. Ok thank you!
            I use your search because it’s great!
            But it breaks the search function of the WPDM (WordPress Download Manager Plugin), which I use on only one page. Therefor I would like to disable it there. I’ll ask my buddy to do that, thought it would be easier…
            Thanks again for your supply!

  1. Hello,

    Is there a way to disable everything about the plugin except adding the user’s searches to the data base?

    pretty much I want to only use Relevanssi for the “did you mean” feature.

    I have the premium version as well.

    Thanks!

    1. John, Relevanssi is a pretty heavy tool if you want just that one feature, as getting it still requires a full index – the better “Did you mean” feature in Premium is based on the Relevanssi index, so you must have that. Free version has a “Did you mean” feature based on logs, but it’s not good enough to be worth the effort.

      So you’d have to have a full index. To disable the search, follow the instructions on this page.

      May I ask, what are you using for search, what’s better than Relevanssi for providing the search results?

      1. Hi Mikko,

        Thanks for your reply. I have a website with over 26,000 products and unfortunately the Relevanssi search isn’t giving satisfactory results. Lots of products have very similar names and when customers search for a specific product, lots of time the search will pull hundreds of items when it clearly should only pull just a few.

        The wordpress default search actually works pretty well with how our customers search.

        The only problem is if a customer spells the product name wrong when searching, I’d like to still have a “did you mean” backup function on our “no search results” page and I like the “clues from the crowd” way of suggesting the “did you mean” term works because we have so much traffic and the names of the products can get very weird and the crowd searches usually end up correctly.

        1. John, in that case uncheck all post types in Relevanssi indexing settings and use the codes on this page to disable Relevanssi searches. To get the user queries in the log, you have to do that manually, but it’s easy: whenever a search is made, run relevanssi_update_log($query, 2); to store the query in the Relevanssi log.

          1. Thanks Mikko,

            I can’t seem to figure out where to put the relevanssi_update_log($query, 2); code. I put it in my functions.php and it seems to just update every query as a blank. Any insight? I appreciate the help.

          2. John, it needs to run whenever there’s a search query made. So, either put it in functions.php and check for is_search(), or put it in the search results template. And yes, it’ll add blank, because $query isn’t defined anywhere – you need to replace that with the actual search query, which you can get from get_search_query(), for example.

          3. By the way, here is my exact code incase anyone wants to replicate this exactly.

            //disable relevanssi main search functions
            remove_filter(‘posts_request’, ‘relevanssi_prevent_default_request’);
            remove_filter(‘the_posts’, ‘relevanssi_query’);

            // This keeps the relevanssi log to keep logging
            add_action( ‘pre_get_posts’, ‘keep_rel_logging’ );

            function keep_rel_logging ( $query ) {

            // Check if on frontend and main query is modified
            if( ! is_admin() && $query->is_main_query() && is_search() ) {

            $log_search_qry = get_search_query();
            relevanssi_update_log($log_search_qry, 2);
            }
            }

  2. Can this also be used to restrict Relevanssi to admin searches only?

    I suppose wrapping the removes in if(!is_admin()) would do the trick?

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *