Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enfold theme live search integration with SearchWP (version 4 and version 3)
<?php
// **********************************************************************//
// Enfold Search WP integration */
// **********************************************************************//
add_filter( 'avf_ajax_search_function', 'avia_init_searchwp', 10, 4 );
function avia_init_searchwp( $function_name, $search_query, $search_parameters, $defaults ) {
$function_name = class_exists( 'SWP_Query' ) ? 'avia_searchwp_search' : $function_name;
return $function_name;
}
function avia_searchwp_search( $search_query, $search_parameters, $defaults ) {
$searchwp_query = new SWP_Query( array(
'engine' => 'default',
's' => isset( $search_parameters['s'] ) ? sanitize_text_field( urldecode( $search_parameters['s'] ) ) : '',
'posts_per_page' => 5,
'fields' => 'ids',
) );
if ( ! empty( $searchwp_query->posts ) ) {
foreach ( $searchwp_query->posts as $key => $result ) {
$searchwp_query->posts[ $key ] = get_post( $result );
$searchwp_query->posts[ $key ]->post_excerpt = get_the_excerpt( $result );
}
}
return $searchwp_query->posts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment