• Resolved mdjako93

    (@mdjako93)


    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 4 months, 4 weeks ago by mdjako93.
    • This topic was modified 4 months, 4 weeks ago by mdjako93. Reason: CodeSnippet

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

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.