Posted on

Toolset Views

Toolset Views

Relevanssi works fine with Toolset, thanks to a lot of compatibility code the makers of Toolset have included in it to make it work with Relevanssi. However, everything doesn’t work automatically without modifications. The key thing to notice with Toolset is that query variables and filters don’t work the way you’d expect.

Because of the way the Toolset Relevanssi compatibility is built, the query variables are not passed to Relevanssi from the search query like they are when Toolset is not involved. This may lead to confusion, when adding a query variable (for example &post_types=page) to the URL has no effect on the results, even though you can tell for sure the search is powered by Relevanssi. The reason is simple: Relevanssi doesn’t see that query variable, because Toolset does not pass it to Relevanssi.

Fortunately Toolset provides means to fix this. There’s a filter hook you can use to modify the query that Toolset passes to Relevanssi. If you want to pass the post type parameter to Relevanssi, you can add this to your theme functions.php:

add_filter( 'toolset_action_toolset_relevanssi_do_query_before', 'rlv_post_type_filter' );
function rlv_post_type_filter( $query ) {
    if ( isset( $_REQUEST['post_types'] ) ) {
        $query->query_vars['post_types'] = sanitize_text_field( $_REQUEST['post_types'] );

This will read the post_types parameter from the query and will pass it to Relevanssi.

If you want to use the date range parameters, that won’t work with the code example on the page. However, to make that code work with Toolset, all you need to do is to replace this:

add_filter( 'relevanssi_modify_wp_query', 'rlv_date_between' );

with this:

add_filter( 'toolset_action_toolset_relevanssi_do_query_before', 'rlv_date_between' );

and it will work fine with Toolset.

6 comments Toolset Views

  1. I’m a newcomer and I’ve been working on our hompage “” for the foundation. For the search I bought relevanssi, but it does not work. I will not get it set. You’re my savior. If I send you access to Dashboard WordPress, are you so nice and can you hire me? I would like to search in PDF, Word or Odt files in the body, which are stored in the library and linked to the static page “News and DRA / LL”. Only name, company and address are to be searched. Your effort will of course be paid.

    best regards


    I wrote it from german to english with the google translator.

  2. So I can add-in some custom post types, what about the ordering of the results? I know the view has an “order option” but I want it to work where it shows the results in the way that relevanssi returns them.

    Is there a method for this or does it already work that way?

  3. There is a compatibility issue between Toolset and Relevanssi. I reported it to Toolset’s support a few months ago, it was replicated, confirmed and it is still in “Known Issues” on their website. It looks like they haven’t been able to make progress yet.

    The issue is: I have designed an archive loop for the search results in Toolset. Relevanssi takes care of the relevance. All is fine, until you add filters and give the visitor the possibility to filter the results by taxonomies or custom fields.

    When Relevanssi is activated, only the options for the items from the current page are displayed. The filter options related to items which are on Page 2, 3 and so on, are not initially displayed. When you get to Page 2, options which are only related to items from Page 1 will disappear. After an AJAX event it usually gets fixed, but of course only until the next page load.

    With Relevanssi deactivated, all filter options appear, also those which are related to items from other pages of the search results loop. The filters work in the way they are expected to work. But then of course, the results are not sorted by relevance.

    I added this filter (toolset_action_toolset_relevanssi_do_query_before), but it doesn’t seem to make a difference, as far as my issue is concerned.

    Perhaps you know why it happens or can think of a solution?
    I wish Relevanssi could work well with Toolset, but for now, I’d say compatibility is only partial.

    Kind regards

    1. Tom, the problem here is that I don’t really know much about how Toolset works; I’ve tried to understand it in the past, but it’s so complicated and so unlike anything else, I haven’t really been able to figure it out (it’s very much a solution to someone else’s problems, not mine).

      But it looks like the filtering options are being generated from the currently available search results. That’s not a Toolset-specific problem, but a wider problem with WordPress: when you load a search results page like that, WordPress just doesn’t see all the results. WordPress sees just the ten results or whatever it is you show on that very page. The rest, they don’t really exist.

      So even without Toolset, doing something like this requires a bit of extra hacking and additional queries. To be able to produce a filter that shows the possibilities from all search results found requires you to first do a search that fetches ALL the results, then study that to figure out the filtering options available, then do a search that gets the 10 posts you want to show on the page. That’s rather complicated even without Toolset involved, and complicated and slow enough that I probably wouldn’t even start trying to do it, and would instead come up with something else.

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 *