Search WP Integration Enfold

// //
// SEARCHWP 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( ‘SearchWP’ ) ? ‘avia_searchwp_search’ : $function_name;
return $function_name;
}

function avia_searchwp_search( $search_query, $search_parameters, $defaults ) {
$searchwp = SearchWP::instance();
$engine_name = ‘default’; // you can swap in your Supplemental Search Engine name
parse_str( $search_query, $output );
$search_string = isset( $output[‘s’] ) ? sanitize_text_field( urldecode( $output[‘s’] ) ) : ”;

// limit the results to 5
function avia_searchwp_search_num_results() {
    return 5;
}
add_filter( 'searchwp_posts_per_page', 'avia_searchwp_search_num_results' );

$posts = $searchwp->search( $engine_name, $search_string );
return $posts;

}