Support

Account

Home Forums Backend Issues (wp-admin) fields overwriting eachohter

Solved

fields overwriting eachohter

  • *Sorry for the typo in the title
    Hey guys,
    hope you are all doing ok 🙂

    Yesterday I had an issue with the way fields are named when grouped or not.
    It might be something that should have been obvious but to me it was a first running into this issue.

    I am currently in a transition stage from the free Advanced Custom Fields to the Pro version.
    And though we are not actively going through all the fields to change them where necessary, we do change them so they are grouped and neatly layed out on the page editor page.

    Now here is the issue.
    I made a field of the type group called “hero
    This group was meant to replace a field set also called “hero

    In the old group I had multiple fields of which I will name 2 below (to make the issue clearer).

    Fieldset: Hero – old
    -> hero_title (type: text)
    -> hero_subtitle (type: text)

    So then I made a new fieldset like this.

    Fieldset: Hero – new
    -> hero (type: group)
    -> title (type: text)
    -> subtitle (type: text)

    Again this is just a part of the full fieldsets but you get the point.

    Now the thing that happend was this.
    When I added the new fieldset, it was added to the top of the fieldset order on the page editor screen.
    When I tried to save the new title and subtitle, they wouldn’t save.
    I tried to debug the php and found that wordpress indeed failed to save the values I entered.

    After much trail and error and a not so good night of sleep…. I was looking in the documentation and the database for the fields in question.
    That’s when I noticed that in the database ACF knows what fields are there and what fieldset and or group they belong to.
    But when it is saved, the field inside the “hero” group is saved as “hero_title” and the same for the subtitle. Which means that it is also saved as “hero_subtitle”

    With this knowlede I tried changing the order of the fieldsets in the page editor screen.
    This worked and now the old fields are overwritten.

    Is this a bug or a thing that was always there and it was just coincidence that I stumbed on this now?

    Cheers.

  • It is something that was there and you found it. The issue is that the fields in both cases are actually named the same and stored in the database under the same meta key, as you have found. This is due to the way that ACF names different field types.

    For normal fields it is simply the name of the field “hero_title”

    Now you have a group field and the way these are names is "{$field_name}_{$sub_field_name}". Unfortunately this results in the same field name “hero_title”.

    You will need to rename either the field or the sub fields.

  • Cool.
    Thank you for the information.

    I thought as much but wanted some confirmation on it.

    Would have been a shame if it was indeed a bug that wasn’t found yet.

    Again thanks for the info.
    Will work on different names.

    Cheers

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘fields overwriting eachohter’ is closed to new replies.