WPML compatibility

This topic contains 4 replies, has 2 voices, and was last updated by weitlaner weitlaner 5 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11232
    weitlaner
    weitlaner
    Participant

    Hi,
    I wanted to inform you that there seems to be an issue concerning the WPML compatibility.
    I’m not sure if this problem is connected to the latest WPML or WP update, we’re currently using the latest version of everything.

    So what is the problem:
    When searching on the English site of our bilingual website (German/English) everything is found within the defined scope and displayed correctly (ID, title, description etc.) the only thing which is wrong is the LINK. It’s always pointing to the base language – which is German in our case – although all posts and pages are mapped correctly via WPML.

    I had no time to track down where this “magic” happens in your plugin but I managed to fix it for now quick and dirty by manipulating the result array in class-asp-search.php as follows:

    if($this->args[‘_wpml_lang’] == ‘en’) {
    foreach($this->results AS $k => $r) {
    switch($r->post_type) {
    case ‘page’:
    $this->results[$k]->link = “https://MYDOMAIN/en/?page_id=”.$r->id;
    break;
    case ‘post’;
    $this->results[$k]->link = “https://MYDOMAIN/en/?p=”.$r->id;
    break;
    }
    }
    }

    This works fine as the url with the id param is correctly resolved to the specific permalink but of course this is only a temporary solution.

    Looking forward to your feedback.

    Kind regards,

    Wolfgang

    #11240
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Wolfgang,

    Issues with WPML usually happen if the Custom Ajax Handler is enabled. It’s a great performance tuning option, but it may lead to such errors. Please check if it’s enabled, and if so, make sure to turn it off instead: https://i.imgur.com/IG2m6Zu.png

    Otherwise I won’t be able to tell unless I’m able to see and debug the issue directly via FTP. The fact that the title and the content are okay tells me that some aspects might not been initialized correctly when requesting the post URL, or this might be a yet unknown issue specific to a combination of plugins.

    Feel free to update your ticket information with temporary back-end and FTP details, and I will check the problem and try to find the cause and fix it if possible.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #11245
    weitlaner
    weitlaner
    Participant

    Hi Ernest,

    thanks for your reply.
    I’ve tried to turn off the custom Ajax Handler but it didn’t help.
    But what I’ve accidently noticed during this attempt is that the issue is obviously related to caching (i.e. WP Rocket in our case).
    When I’m logged in to the WP backend (caching is completely disabled for the admin session) all search results are OK. As soon as I log off all search result links are being resolved to the base language as described above ….
    Anyway this seems strange to me. If the search scope is correct (the WPML language param correctly passed) and also the entire result including postID, title, description etc., why the link is not set correctly at the same time together with everything else?
    Unfortunately I cannot provide access to the backend on the production server so I have to stick with my quick & dirty fix for the moment. Maybe you’ll get other request in the near future as there should be quite a lot of people using a similar setup.

    Kind regards,
    Wolfgang

    #11253
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Wolfgang,

    That is indeed interesting. The results link is requested with the get_permalink( $id ) core functions, which always should return the correct URL, as WPML nicely appends a filter to it to make the appropriate modifications. My guess is, that for some reason this filter might be malfunctioning or removed during the caching process for ajax requests (?) and not changing the URL as it should.

    I did some googling around and found that others have had similar issues with WPML, but the reason was never specified. Someone actually found a possible solution, which may work here as well. I’ve combined his solution with a filter, it’s worth a try. Put this into the functions.php file in your active theme directory (copy from line 3):

    Try removing your solution temporarily to see if this works. If so, then I recommend using this one instead, as this won’t be removed after a plugin update. Let me know if this does anything at all.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #11256
    weitlaner
    weitlaner
    Participant

    Hi Ernest,

    thanks for googling!
    Unfortunately it didn’t solve the problem. I already had tried the same thing with the icl_object_id() (by the way this method is marked as deprecated and will be removed from WPML 3.3).
    But thank you anyway for the hint to move it to a filter function. This way I can use my custom hook as well.

    Kind regards,
    Wolfgang

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.