• Resolved ig_communitysites

    (@ig_communitysites)


    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!

    https://wordpress.org/plugins/qtranslate-x/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author John Clause

    (@johnclause)

    Are all those fields are distinguished by some name in “class” attribute? If so, then simply add that class name into option “Custom Fields”.

    Thread Starter ig_communitysites

    (@ig_communitysites)

    No, ACF just adds very basic, generic class attributes. Here’s an example field:

    `<input type=”text” id=”acf-field-catalogue_item_metadata_contributor” class=”text” name=”fields[field_536b984656093]” value=”” placeholder=””>

    Plugin Author John Clause

    (@johnclause)

    On this example id=acf-field-catalogue_item_metadata_contributor, so put id acf-field-catalogue_item_metadata_contributor into “Custom Fields/id”.

    Are there fields that you need and they are not identified by id or class?

    Thread Starter ig_communitysites

    (@ig_communitysites)

    Thanks for your help, John, but that isn’t the issue. I have indeed set up the fields via their ID value, and that works fine on the form itself.

    But it doesn’t work when the data is saved and passed through the $_POST array…because that uses the “name” attribute. Because of the way that qTranslate-X changes the field names, you end up with input name attributes like this:

    fields[field_536b984656093]_edit

    …which results in the data not coming through correctly in the $_POST array. When you change it to:

    edit_fields[field_536b984656093]

    it all works fine.

    Plugin Author John Clause

    (@johnclause)

    Change of name-edit to edit-name was done long time ago as a part of making ACF to work, I hope you are using the latest version?

    So, you would need to put values like field_536b984656093in “Custom Fields/id” for each field you want to be translatable. Once field is created, the numerical part of field name does not change, which makes it ok. It would be easier if they set some unique class name for their fields. We may suggest this to them, once we make sure that everything else is ok.

    Is there anything left not working?

    Plugin Author John Clause

    (@johnclause)

    @ig_communitysites: Have you seen this plugin: https://wordpress.org/plugins/acf-qtranslate

    Turn on “Compatibility Functions” in -x, when you try it.

    Thread Starter ig_communitysites

    (@ig_communitysites)

    Thanks very much for your patience, John. You’re quite right: upgrading both your plugin (which was on v3.9.6) and ACF (which was on v4.3.4) means that it works out of the box. Bingo. I’m going to give myself a slap on the wrist for not trying an upgrade of ACF sooner.

    So, there’s only one thing which doesn’t work…and I don’t imagine this is going to be an easy one! ACF allows you to add custom fields to taxonomies as well as posts. It adds those custom fields to the taxonomy/category form via AJAX calls. Any suggestions on how I can make those work?!

    Plugin Author John Clause

    (@johnclause)

    I need to investigate how that work. Does this prevent you from you need to do, or this would be a convenience feature?

    Thread Starter ig_communitysites

    (@ig_communitysites)

    To be honest, it does cause us problems as we use taxonomies with custom fields quite a lot. I’m investigating whether I can get it working myself, so will post anything I manage to work out.

    Thread Starter ig_communitysites

    (@ig_communitysites)

    Having done some further testing, it looks as if the only thing which stops it from working is that the custom fields are loaded into the taxonomy form via AJAX and so aren’t present when the initial qTranslate field setup takes place.

    If I add something like this into edit-tag.js:

    setTimeout(function() {
                qtx.addContentHookByIdC('acf-field-category-subtitle', form);
            }, 5000);

    then the addContentHookByIdC call takes place after ACF’s AJAX call has returned and the acf-field-category-subtitle field is set up correctly for qTranslate.

    (I realise that’s a very crude method! It hopefully demonstrates that the timing of the addContentHookByIdC call is the only problem, though.)

    Plugin Author John Clause

    (@johnclause)

    Hi @ig_communitysites, plugin “ACF qTranslate” https://wordpress.org/plugins/acf-qtranslate/ has just been updated to be copatible with qTranslate-X: https://github.com/qTranslate-Team/qtranslate-x/pull/40

    The new plugin is on GitHub too: https://github.com/funkjedi/acf-qtranslate/issues. Please communicate with its author for further improvements if needed: https://wordpress.org/support/plugin/acf-qtranslate

    Thread Starter ig_communitysites

    (@ig_communitysites)

    Thanks, John. Yes, it looks like that works very well. Great stuff.

    vbkun

    (@vbkun)

    Anyone knows if this still actually works?

    Just installed qtranslate x ( 3.2.9 ) + Advanced Custom Fields ( 4.4.1 )+ acf qtranslate (1.7.6) and isn’t really working, seems something is odd in the field filtering, its leaving ‘left overs’ and the vaues just keep pilling up like:

    “[:pt-br]oi?[:pt-br][:pt-br]<!–:pt-br–><!–:pt-br–><!–:pt-br–><!–:pt-br–>soi?” (this is actually what shows up in my seccondary language, english)

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Getting qTranslate-X to work with Advanced Custom Fields’ is closed to new replies.