Use SearchWP instead of the standard search

SearchWP is an advanced search engine for WordPress. You can use it with Enfold without any additional configuration. If you want to use it with the ajax search function (preview search results when you click on the magnifier icon) then insert this code into the child theme functions.php file or into the enfold/functions.php file:

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;
}

Troubleshooting

In case you get 404 error on your archive pages, please try de-activating SearchWP plugin and check if it is the culprit. If it is, please add following code to Functions.php file as well


function my_searchwp_maybe_short_circuit() {
	if ( is_archive() ) {
		add_filter( 'searchwp_short_circuit', '__return_true' );
	}
}

add_action( 'wp', 'my_searchwp_maybe_short_circuit', 999 );