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.

This topic contains 14 replies, has 3 voices.

Last updated by jean-philippeU 3 weeks ago.

Assigned support staff: Sumit.

Author Posts
September 18, 2019 at 11:19 pm

grahamS-3

* Numbers indicate associated screen shot or item within the screen shot*

I am trying to:
1. Use a custom post type called "Videos" to store information about videos
2. The video information is stored in ACF fields
3. Each video will be translated, including the ACF fields.
4. I also have ACF fields set up for pages that allow the admin to choose a video (as a post object).

When I pull the ACF field, I get different results for the English page and the Spanish page (see link below).

How do a use WPML and ACF to get the correct language for the Video post?

Here is the code snippet from pages.php

echo '<pre>';
		echo 'var_dump( get_field(\'video\') ):';
		echo '<br>';
		var_dump( get_field('video') );		
		echo '</pre>';

Link to a page where the issue can be seen:
hidden link

I expected to see:
The Spanish/English version of the Video post, as appropriate, based on language.

Instead, I got:
The post object in the English version and the post ID (string) in the Spanish version.

September 19, 2019 at 2:15 pm #4606095

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

Thank you for contacting support forum.

I think the post object should be translated automatically and you don't need to translate the ID manually.
Could you please share the screenshot of translation editor when translating page which holds the post object?

Also, could you please set the additional info filed to copy instead of translation and then test with a new page?

Thanks

September 19, 2019 at 2:45 pm #4606479

grahamS-3

Hi Sumit,

First, thank you for taking the time. I really appreciate it.

I have attached the screen shot of what I see when doing the translation for Video Test.

I changed the translation setting on Additional Info to "Copy" and made a new page but it seems to be the same as the other one so far:

hidden link

Please let me know what you need from me.

Thanks so much,
Graham

September 20, 2019 at 12:57 pm #4612343

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Graham,

Thanks for the info. I need to check the issue myself so I need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.
Instructions to send private information are here: hidden link

Privacy and Security when Providing Debug Information for Support:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Thanks

September 20, 2019 at 2:14 pm #4612949

grahamS-3

Hi Sumit - I can get all of this info, but I filled out these fields on the initial submission. Did that info not come through? The info I submitted is the test site. The real site is on my localhost.

I'll put this info together right now. I just thought I would let you know that the info I submitted is fine to use.

September 20, 2019 at 2:51 pm #4613061

grahamS-3

OK, I found the info but now I don't have the option to use the form to send it. Maybe it's because the last reply on the thread is from me. Odd. Anyway, I guess I can't submit it until you reply but I did confirm that it is attached to the first submission.

Thanks for digging into this,
Graham

September 20, 2019 at 3:13 pm #4613247

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Graham,

Yes, Thanks! I noticed but I just wanted to confirm.
Okay, so I checked the site and I noticed a couple of issues:-

#1 When Fields group set to translatable then you need to duplicate the fields group to secondary language as well. Like described here hidden link
I did that for now.

#2 Since the field contains an object and no real string to translate thus we need to set the custom fields to copy but also we need to set the system fields to copy as well.
Edit the page > Scroll down to multilingual content setup > Show system fields and then set the fields with an underscore to copy as well. I did that too.
And now you can see the translated filed object here hidden link

Does it fix the issue for you?

Thanks

September 20, 2019 at 4:55 pm #4613681

grahamS-3

Hi Sumit,

This is awesome! It's exactly what I needed. The only thing is, I can't seem to follow the directions on the page you linked to.

----------
#1

It says:

"Before creating a field group, please enable the “Field Groups” post type for translation. This is possible via the WPML -> Translation management page."

When I do that, I don't see the same thing as in the screen shot. I have attached what I see.

----------

Basically, I want to follow whatever you did on my local install so that I can do it again for other fields. I'm still stuck. What am I missing here?

Thanks,
Graham

September 23, 2019 at 8:56 am #4621823

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

I am sorry but this message is outdated.
Now this setting is located in WPML > Settings > Post type translation.

There you can find Fields Group and then please select "Translatable - only show translated items".

Please note, you need to select the fields group to translatable only if you want to translate the fields label now or in future. For just translating values fields group doesn't need to be translatable and thus it will save you some time and disk space for DB.

If you have any concern or question then please let me know before applying changes.

Thanks

September 24, 2019 at 11:22 pm #4634405

grahamS-3

Hi Sumit,

I guess this is hard for me because even though some of this is working, I don't really understand WHY it's working. I just created a new ACF Field Group called Colors. The repeater field is called Color Names (color_names). The text field inside is called Color Name (color_name). I set Color Name to "Copy" and Color Names to "Translate".

I then created a page called Colors and made the field group visible only on that page.

I am using this code to view the fields:

echo 'var_dump( get_field(\'color_names\') ):';
echo '<br>';
$color_names = get_field('color_names');
var_dump( $color_names );
echo '<br>';
echo '$color_names:';
echo '<br>';
echo $color_names;

I added two colors, "Green" and "Blue". On the front end I get this:

var_dump( get_field('color_names') ):
array(2) {
  [0]=>
  array(1) {
    ["color_name"]=>
    string(5) "Green"
  }
  [1]=>
  array(1) {
    ["color_name"]=>
    string(4) "Blue"
  }
}

$color_names:
Array

I then add the translation, and switch to Spanish. Then I get this:

var_dump( get_field('color_names') ):
string(1) "2"

$color_names:
2

It seems like the only way to make this work is to actually edit the way the ACF fields are translated ON a page/post. I go to "Multilingual Content Setup" and I change "_color_names" to "Copy". When I do that, I get this on the Spanish page:

var_dump( get_field('color_names') ):
array(2) {
  [0]=>
  array(1) {
    ["color_name"]=>
    string(5) "Verde"
  }
  [1]=>
  array(1) {
    ["color_name"]=>
    string(4) "Azul"
  }
}

$color_names:
Array

Obviously that means it's working, but is it really true that the only way to make this work is to edit the translation settings from a content item? That just seems like it can't be right.

The main reason I'm asking is because making this change to the way the fields work seems to carry over to new pages. Anyway, if this is the way it is, then I guess that is fine. It just doesn't feel like the proper way to do it.

Oh, by the way, I did this on my local host, not the staging site I sent to you.

Thanks,
Graham

September 25, 2019 at 12:02 am #4634507

grahamS-3

Hi Sumit,

Sorry to submit again already, but I was feeling confident enough to start working on the actual website that I am developing and I am stuck again. I confirmed that the ACF Field Groups post type was set to "Translatable - only show translated items" (see screen shot). That is what it is set to in my other site where this is working.

But, when I go to create a new Field Group, there is no field to set the translatabiliity of the fields (see screen shot). There isn't one for the field group itself and there isn't one for the fields within it.

Just as a point of clarification, I only need the visitor-facing portion of the website to be translated. The admins who will work with the translated content will be bilingual so I don't need to translate ACF field labels. I don't know if that changes anything but one of the frustrating things about the documentation is I sometimes can't tell if I'm working on something for the admin side or the visitor side.

Please let me know if there is anything I can do to help. I build WordPress websites for a living and I don't recall being this confused by a plugin in quite a while.

Thanks,
Graham

September 25, 2019 at 1:10 pm #4639025

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Graham,

I am really sorry for the bad experience.

1. System fields are not set to copy automatically
Yes, I understand that. This is just a workaround we have a ticket already and the development is in progress to set those field to copy when actual field set to copy.
So very soon it will be fixed.

Now about the question that how many times you have to set the field to copy.
Only once. The setting is global so if you set the field for one post it is not needed to set for another post. The field setting is saved and the same setting will be used globally.

2. Issue on live site
I don't have the credential of the live site so I can not check but I am guessing, please make sure you have installed and activated our bridge plugin ACF Multilingual. Could you please confirm?

3. I only need the visitor-facing portion of the website to be translated.
The labels you put in the backend are not for admins. Those labels can be used to display on front-end e.g. Color: Gray where Color is the label you've defined in ACF setting and Gray is the value you have entered in for the specific post.
So when Color needs the translation we have to translate the whole ACF group or if we are just displaying values on front-end then we are fine without translating ACF field groups.
Does it make sense?

Thanks

September 25, 2019 at 3:38 pm #4640659

jean-philippeU

Hi,

I am currently developing a website and I am observing the same problem for a custom post type with three ACF Object Articles custom fields. They are all set to "Copy". Also, I've set the system fields to "Copy".

One thing I am noticing is that when I save the post in the original language, the meta_value of the original posts have the correct ID and the translated IDs are copied to the meta_value
of translated posts. All is good until I update the translation in the translation editor. On save, the meta_value of the translated posts are updated back to the original language IDs.

The screenshots attached are showing the problem I have for one of my custom field.

1490 and 1491 are in the original language post ids
1493 and 1494 are the respective translated post ids

For the ACF Object Article field :
998 and 746 are the linked post type IDs in the original language
899 and 1037 are the linked post type IDs in the translated language

September 25, 2019 at 3:42 pm #4640709

jean-philippeU

Right now, to solve my issue, I am using the 'wpml_object_id'.

September 25, 2019 at 3:54 pm #4640791

jean-philippeU

Actually, the wpml_object_id filter does not resolve my issue as I am querying the custom fields ids which are not in the right language.

Also, I've noticed that regardless of whether the system fields are set to "Copy" or "Don't translate". The same behavior is observed on the meta_value.

The topic ‘[Closed] ACF Post Object Not Returning Translation with get_field’ is closed to new replies.