Created
March 11, 2021 14:16
-
-
Save jchristopher/39cf1f628dd678fabc64021ee5dc503b to your computer and use it in GitHub Desktop.
Integrate SearchWP with JetSmartFilters search using JetEngine Listing Grid to display results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Integrate SearchWP with JetSmartFilters search using | |
// JetEngine Listing Grid to display results. | |
add_action( 'pre_get_posts', function( $wp_query ) { | |
if ( | |
! isset( $wp_query->query['jet_smart_filters' ] ) | |
|| empty( $wp_query->query['s'] ) | |
) { | |
return; | |
} | |
$swp_query = new \SWP_Query( array( | |
'engine' => 'default', | |
's' => $wp_query->query['s'], | |
'fields' => 'ids', | |
'nopaging' => true | |
) ); | |
$results = ! empty( $swp_query->posts ) ? $swp_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 ); | |
}, 9999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a trillion!