Skip to content

Instantly share code, notes, and snippets.

@msaari
Created June 18, 2022 01:53
Show Gist options
  • Save msaari/6191723043ea4c687fb29b4adc19da36 to your computer and use it in GitHub Desktop.
Save msaari/6191723043ea4c687fb29b4adc19da36 to your computer and use it in GitHub Desktop.
JetSmartFilters Relevanssi fix
<?php
add_action( 'pre_get_posts', 'rlv_jetsmartfilters', 9999 );
/**
* Makes JetSmartFilters use posts from Relevanssi.
*
* @param WP_Query $wp_query The wp_query object.
*/
function rlv_jetsmartfilters( $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,
);
$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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment