Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jeFFF-73

    (@jefff-73)

    This is the code I found on the algolia website, as the process changed I guess this solution is not working anymore.
    It should add these data ‘wpml.locale’ in the post indexed and I have to filter the results afterwards.

    <?php
    
    // Add the locale of every post to every record of every post type indexed.
    function add_locales_to_records( array $attrs, WP_Post $post ) {
        // Here we make sure we push the post's language data to Algolia.
        $attrs['wpml'] = apply_filters( 'wpml_post_language_details', null,  $post->ID );
        return $attrs;
    }
    add_filter( 'algolia_post_shared_attributes', 'add_locales_to_records', 10, 2 );
    add_filter( 'algolia_searchable_post_shared_attributes', 'add_locales_to_records', 10, 2 );
    
    // Register the locale attribute as an Algolia facet which will allow us to filter on the current displayed locale.
    function add_locale_to_facets( array $settings ) {
        $settings['attributesForFaceting'][] = 'wpml.locale';
    
        return $settings;
    }
    add_filter( 'algolia_searchable_posts_index_settings', 'add_locale_to_facets' );
    add_filter( 'algolia_posts_index_settings', 'add_locale_to_facets' );
    
    // Expose the current locale of the displayed page in JavaScript.
    function enqueue_locale() {
        wp_add_inline_script( 'algolia-search', sprintf('var current_locale = "%s";', get_locale()), 'before' );
    }
    add_action( 'wp_enqueue_scripts', 'enqueue_locale', 99 );
    • This reply was modified 5 years, 2 months ago by jeFFF-73.
    • This reply was modified 5 years, 2 months ago by jeFFF-73.

    Works for me too ! ??
    WP : 4.5.3
    Plugin : 3.2.0.2

    jeFFF-73

    (@jefff-73)

    An update,
    It is actually working but you have to deactivate WPML and reactivate it.
    I did that and everything is working fine now.

    jeFFF-73

    (@jefff-73)

    Hello,
    I use WPML 3.2.7 and this issue is still on.
    Everything works fine when I deactivate WPML
    Chees

Viewing 4 replies - 1 through 4 (of 4 total)