WPML – Algolia – Search Results Page

Just want to share my solution to filter WPML results on the Search Page.

It took me 10 days to find solution for this, it kept returning the wrong numbers for pagination, and often there would be a different number of products on the results page.
After this, everything works as it should:

function eRaccoon_custom_algolia_search_params($params) {
if (function_exists('wpml_get_current_language')) {
$params['filters'] = "wpml.locale:" . wpml_get_current_language();
}
return $params;
}
add_filter('algolia_search_params', 'eRaccoon_custom_algolia_search_params');
function eRaccoon_custom_post_shared_attributes(array $shared_attributes, WP_Post $post) {
if (function_exists('wpml_get_post_language_details')) {
$lang_details = wpml_get_post_language_details($post->ID);
$shared_attributes['wpml.locale'] = $lang_details['language_code'];
}return $shared_attributes;
}
add_filter('algolia_post_shared_attributes', 'eRaccoon_custom_post_shared_attributes', 10, 2);

Cheers!

  • This topic was modified 6 hours, 40 minutes ago by mdjako93.
  • This topic was modified 6 hours, 40 minutes ago by mdjako93. Reason: CodeSnippet

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer