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.