• Resolved dartrax

    (@dartrax)


    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?

    • This topic was modified 3 years, 8 months ago by dartrax.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Unfortunately, the entire search implementation on our end is not optimal. It’s due to the way the plugin works, and making search work is not that simple. If it works for you, you can move forward with the implementation.

    If there`s anything else, please let us know!

    Kind Regards,

    Thread Starter dartrax

    (@dartrax)

    Hi anghelemanuel99,
    thank you for your quick and honest reply!
    Yes, it’s working really fine, I’m very pleased with translatepress generally, and the live search works perfect. I just wasn’t sure about that force_search-thing and suspected myself of having overlooked something, but that may not be the case, if you say so ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ajax live search dropdown with Flatsome theme’ is closed to new replies.