Tagged: SearchWP
Hello I tried to change the Search engine to SearchWP.
I installed SearchWP, changed the theme to the child theme and tried to add the following code from this article to the chilled theme functions.php
Article: https://kriesi.at/documentation/enfold/search/
Code:
`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;
}
When I add it and want to save it it just doesn’t work.
Hey lewy9,
What do you mean by “it does not work”? The search is working. How are you testing it?
Best regards,
Victoria
Yes the search does work, but the code to the function php for searchWP I can’t save the php that’s what I meant by not working
Hi lewy9,
What is the error that you’re getting?
Best regards,
Victoria