Replies: 0
Hi!
I’ve noticed that the live search functionality of the Flatsome theme does not find translated content. I’ve looked into the code and found out that Flatsome provides a filter to add search results to the live search, called flatsome_ajax_search_function. Now I just need a function to get search results out of the translated products/posts base. I noticed that translatePress extends the standard wordpress query, but this only works for the main query, not for auxiliary ones. There seems to be a workaround built in with the trp_force_search filter, and I was able to get it work with that, but my solution seems not to be so elegant.
I added this to functions.php:
$dartrax_force_search;
add_filter('flatsome_ajax_search_function', function() {
return 'dartrax_live_search';
}, 10, 2 );
function dartrax_live_search($search_query, $args, $defaults) {
global $dartrax_force_search;
$dartrax_force_search = true;
$posts = get_posts($args);
$dartrax_force_search = false;
return $posts;
}
add_filter('trp_force_search', function() {
global $dartrax_force_search;
return $dartrax_force_search;
});
Could you please take a look at my approach and tell me how to do it not the hacky way? Is there a trp search function that I can use instead of that force_search filter thing?