• I noticed in the Relevanssi changelog that JetSmartFilters compatibility was added, but there are still some issues when filtering results.

    When using a search filter it appears to do a general WordPress search rather than searching within the current selection/query. I created a custom post type and am trying to search within the results of that post type using a jet search filter, but after searching it shows results from all posts.

    I have tried adding code taken from your support section to disable Relevanssi on that page, but it did not work, and the results are returned as expected as soon as Relevanssi is disabled.

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    The Relevanssi JetSmartFilters compatibility mode actually resets all post type parameters, so that’s what breaks this. I don’t have JetSmartFilters, so I can’t investigate this. I am currently sorting out this exact issue with a Relevanssi Premium client and so far have no luck – my initial suggestion doesn’t seem to work.

    Here’s how you can try disabling Relevanssi:

    add_action( 'init', function() {
    remove_action( 'pre_get_posts', 'relevanssi_jetsmartfilters', 9999 );
    }, 999 );

    add_action( 'pre_get_posts', function( $wp_query ) {
    if (
    ! isset( $wp_query->query['jet_smart_filters'] )
    || empty( $wp_query->query['s'] )
    ) {
    return;
    }

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

    I suggested something like this:

    add_action( 'init', function() {
    remove_action( 'pre_get_posts', 'relevanssi_jetsmartfilters_post_type', 9999 );
    add_action( 'pre_get_posts', 'rlv_jetsmartfilters_post_type', 9999 );
    }

    /**
    * Makes JetSmartFilters use posts from Relevanssi.
    *
    * @param WP_Query $wp_query The wp_query object.
    */
    function rlv_jetsmartfilters_post_type( $wp_query ) {
    if (
    ! isset( $wp_query->query['jet_smart_filters'] )
    || empty( $wp_query->query['s'] )
    ) {
    return;
    }

    $args = array(
    's' => $wp_query->query['s'],
    'fields' => 'ids',
    'posts_per_page' => -1,
    'relevanssi' => true,
    );

    if ( this is a post type archive, or JetSmartFilter has a post type parameter ) {
    $args['post_type'] = get the post type value somewhere;
    }

    $relevanssi_query = new WP_Query( $args );

    $results = ! empty( $relevanssi_query->posts )
    ? $relevanssi_query->posts
    : array( 0 );

    $wp_query->set( 'post__in', $results );
    $wp_query->set( 'post_type', 'any' );
    $wp_query->set( 'post_status', 'any' );
    $wp_query->set( 'orderby', 'post__in' );
    $wp_query->set( 'order', 'DESC' );
    $wp_query->set( 's', false );
    }

    This way, you could get the post type restriction to kick in. But this didn’t work for my client. I’m not sure why.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.