• Resolved Pavel Mares

    (@pavelmares)


    Is there a way to integrate it? Any plans? We are currently trying the plugin and works like a charm, but multilang content is an issue for us.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Closest we have at the moment would be something mimicked from https://github.com/WebDevStudios/wp-search-with-algolia/wiki/WPML

    There we have example code to get the current locale attached to each post and then how to use that newly indexed attribute to filter based on current locale for the user.

    Thread Starter Pavel Mares

    (@pavelmares)

    Yeah, that is kinda a way, but not exactly. I thought of another way, for autocomplete at least. Since your plugin already offloads the polylang taxonomy correctly, I figured I can highjack the request. Can you validate on your end? For me it does seems to work.

    Currently I am forcing lang type, but that can be gathered from current page. This logic / idea is based on algolia search index I tried to filter with.

    What to you think? The template currently does work for us by default, because it searches with polylang overwriting for only current language (it has problems that we will have to remove paginations sice that poses an issue).

    // Store the original send method
    const originalSend = XMLHttpRequest.prototype.send;

    // Replace with our proxy
    XMLHttpRequest.prototype.send = function(body) {
    // Check if this is an Algolia request by examining the URL
    // 'this' refers to the XMLHttpRequest instance
    if (this._url && this._url.includes('algolia.net/1/indexes')) {
    // Parse the body
    let bodyData = JSON.parse(body);

    // Add your custom filter
    bodyData.filters = "taxonomies.language:CZ";

    // Replace with modified data
    body = JSON.stringify(bodyData);
    }

    // Call original send with our modified body
    return originalSend.call(this, body);
    };

    // Capture the URL when open is called
    const originalOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
    this._url = url;
    return originalOpen.apply(this, arguments);
    };

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I guess I’m not completely certain what the endgoal is for your usecase. The wiki page I linked to is basically just properly showing a result by current locale. Both English and Czech version of a post are in the index, and conditionally show just one of them.

    What type of integration are you trying to do based on PolyLang?

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

The topic ‘Polylang support’ is closed to new replies.