Getting qTranslate-X to work with Advanced Custom Fields
-
Hi,
Just posting this in case it helps anyone else…
I’ve been struggling to get qTranslate-X to work with Advanced Custom Fields. If I configure the custom fields as described in the FAQ, they work fine in the post editing form, correctly switching languages and showing the right values. But when I save the post, only the currently-displayed language ends up in the post’s metadata (and only that value is in the submitted form data). It never saves the multilingual data.
Having done lots of testing, I worked out that the problem was with the naming of the visible version of the field. Line #344(ish) of the un-minified qtranslate.js is this:
inpField.name+=’_edit’;
which creates a field called (for example) myfield1_edit to accompany a hidden, multilingual field called myfield1 where the ‘real’ data is stored.
But the way that ACF names its fields means that you end up with a field called this: ‘fields[field_536b984656093]_edit’ to accompany the hidden field called ‘fields[field_536b984656093]’. My guess is that when the post is submitted, that syntactically invalid field name causes the values to get mixed up.
If I change that line to:
inpField.name=”edit_”+inpField.name;
then I get a syntactically-correct field name of ‘edit_fields[field_536b984656093]’, the values come through correctly and it all suddenly works fine.
Hope that saves someone some time!
- The topic ‘Getting qTranslate-X to work with Advanced Custom Fields’ is closed to new replies.