Home › Forums › Bug Reports › Relationship field – Wpml
Hello,
I’ve a problem with advanced custom fields (acf plugin) and WPML.
The translations of the posts work fine but the problem shows up when I use the relationship field.
The primary language works fine. But the relationship field with the secondary languages doesn’t work. Do you know what I can do to fix this ? Did anyone find a solution to this problem ?
When I check in the secondary language what my relationship field contains using var_dump( get_field(‘my_relation_field’) ); i got only an arrow containing the id’s of the original articles and not of the translated onesβ¦
When I check the primary ones, i got the id’s of the same articles which is correct. The others fields related to these posts are well present too.
Do someone know how to fix this ?
Thank you for your help !
Depending on the version of ACF, I get different results.
With an old version of acf, i get an arrow containing the idβs of the original articles and not of the translated ones
OR
with the last version of acf i get array(0) { }
Hi @frg004
ACF is an interface for saving / retrieving custom field data, I think what you are expecting is above what ACF is capable of doing.
For each translated page, you will need to select the values in the relationship field. It will not do this automatically
Hello Elliot,
ACF retrieved perfectly the custom field data when I use the primary language. I’ve also well selected the values for each page in the different language.
I’ve used your tuto (http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/) and it worked perfectly in French (the main language of the website).
But I can’t make it work like this for the secondary languages…
You can check over here :
– Main language (Fr): http://www.velo-montagne.com/sejour-gastronomique/sejour-gastronomique-mi-semaine/ (the table is well generated at the end of the page)
Secondary languages
– (Nl) : http://www.velo-montagne.com/nl/gastronomisch-verblijf/een-midweek-gastronomisch-verblijf/
– (En) : http://www.velo-montagne.com/en/gastronomical-stay/gastronomical-mid-week-stay/
Can you have a look at this ? It’ll help you to undertand what I’m doing…
Do you know how to fix this ? I think that WPML and ACF are very close to make this work but I don’t know how !
Elliot, can you have a look at this problem ?
I can send you a few $ with Paypal if you can help me to correct this quickly ! I really need a solution !
Thank you for your help and understanding π
Hi @frg004
Thanks for the code.
Looking at both URL’s previously posted (fr and en), the var_dump produces an empty array for both…
Are you able to get it working for one language or does it not work on both? If it does not work on both languages, it is possible that the issue could be something else like a spelling mistake on the field name…
Hello Elliot,
Here http://pastebin.com/3FxrprJr ,
you can see the output of “var_dump(get_field(‘relation_sejour_chambre’) );”.
I got all the data’s in French (Primary language) but none in the secondary languages (Nl and En)
As you said, currently both French and En Url’s produce an empty array for both but only since yesterday when Andreas from WPML plugin has asked me to add :
1. this function in my functions file : http://pastebin.com/V3v1UBvP
2. Replace $posts = get_field(‘relation_sejour_chambre’);
with $posts = lang_object_ids( get_field(‘relation_sejour_chambre’), ‘post’ );
Since I did action number 2, I got this error :
Catchable fatal error: Object of class WP_Post could not be converted to string in /homez.533/reloukin/vm/wp-content/plugins/sitepress-multilingual-cms/inc/template-functions.php on line 179
And the result of this error is an empty echo array on the page in the main language french.
If I let action number 2 as it was before, I got a nice arrow in french (main language) and “array(0) { } ” in the secondary languages…
What do you think ?
Thank you for your help !
Hi @frg004
I think the lang_object_ids function will work for you, however you are passing through the wrong parameter.
When you use get_field, the relationship field will return an array of objects. That function requires an array of ID’s
Can you please edit your relationship field to return an array of ID’s and make sure it does by debugging the returned ACF value.
Thanks
E
Hello Elliot,
Thank you for your answer.
I’ve changed the relationship field to return an array of IDβs.
1. In french (main language), I got this result :
“array(6) { [0]=> int(170) [1]=> int(169) [2]=> int(142) [3]=> int(141) [4]=> int(140) [5]=> int(138) } ”
2. In the two secondary languages, I got this result : “array(0) { } ”
It’s like it didn’t record the id’s of the posts in the secondary languages…
What can I do ?
Thank you for your help !
Hello Elliot,
I think that I’ve found the solution. I come back to you later, I’ll make more tests first ! π
Thank you !
Hello Elliot,
Here is what I did to make it work. It was more simple that what we thought π
1. I went to wpml /general settings / translation configuration.
(Sorry if it’s not exactly like this in English, mine is in French..)
2. I check the relationship field. I changed it from “copy of the orginal” to “to translate”.
3. I went back in the post in the secondary languages where Advanced custom fields allow me to select the related posts. There, I removed the already selected post and I added them again. Then, I update my posts.
4. I removed $posts = lang_object_ids( get_field(‘relation_sejour_chambre’), ‘post’ ); and I put back $posts = get_field(‘relation_sejour_chambre’);
5. I went frontend and I updated the page. It worked π
I still have one problem and I’ve create a new ticket for it but I think it’s more something for wpml than for you π : http://wpml.org/forums/topic/wrong-link-to-the-translated-pages-relationship-field-wpml-adv-custom-fields/
Anyway, if you have an idea π
Thank you for the help you gave me Elliot !
The topic ‘Relationship field – Wpml’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.