Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing issues with the auto-translate functionality where the order of team members in the 'The Management Team' section is different on the translated page compared to the original.
Solution:
We have identified that the issue is related to the Post Object and there is a known workaround for it. If you're using a custom order for related posts in a Relationship or Post Object field and notice that the order is not maintained after translation, it's likely because the posts are being ordered by ID instead of the custom order. To fix this, you can add the following code snippet to your theme's

functions.php

file:

add_filter( 'acf/load_value/type=post_object', 'format_order' );
function format_order( $value ){
  
$lang = apply_filters( 'wpml_current_language', null );
    foreach ($value as $key => $id) {
        $type = get_post_type($id);
        $value[$key] = apply_filters( 'wpml_object_id', $id, $type, true, $lang);
    }
return $value;
}

Please note that this solution might be outdated or not applicable to your case. We highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket with us.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: ,

This topic contains 2 replies, has 2 voices.

Last updated by Ilyes 6 months, 4 weeks ago.

Assisted by: Ilyes.

Author Posts
April 22, 2024 at 2:18 pm #15551223

Sven

We are having some issues with the auto translate functionality. On this page there is a "The Management Team" section on the page with some team members.

However on the translated page, the order of the team members is completely different. How do we fix this?

April 24, 2024 at 10:43 pm #15562858

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello Sven,

I have installed the site locally and found the following :

- It wasn't related to automatic translation as the issue replicates even when translating the content manually using the translation editor, you could try it on your staging too.
- The issue seems to be related to the field type (post object) in combination with the custom theme you are using
- I'm yet to replicate the issue on a new environment
- I will share the copy of your site with our 2nd tier for more insight

I will get back to you if I get any updates,

Best,

April 25, 2024 at 2:05 pm #15566092

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

It turns out to be indeed related to the Post Object and we already have a workaround for that, here is how to solve this : https://wpml.org/errata/advanced-custom-field-related-posts-in-relationship-and-post-object-field-dont-keep-custom-order-in-translation/

If you’re using a custom order for related posts in a Relationship or Post Object field, you’ll see the order is not keep when translating the post. Instead, the posts will be ordered by ID.

You can add this snippet to your theme’s functions.php.

add_filter( 'acf/load_value/type=post_object', 'format_order' );
function format_order( $value ){
 
$lang = apply_filters( 'wpml_current_language', null );
    foreach ($value as $key => $id) {
        $type = get_post_type($id);
        $value[$key] = apply_filters( 'wpml_object_id', $id, $type, true, $lang);
    }
return $value;
}

Thank you for your patience!

April 25, 2024 at 2:23 pm #15566186

Sven

Hi Ilyes,

Thank you, works perfeclty! 🙂