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.

2 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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.