Home Forums Backend Issues (wp-admin) update_field for Taxonomy as additive/incremental?


update_field for Taxonomy as additive/incremental?

  • On a Taxonomy, “Organisation”, I have used an ACF field group containing a “Taxonomy” field for another taxonomy, “Topic”, so as to categorise organisations.

    The following code successfully forges the relationship to the Topic term 12076 for the company in question…

    update_field( 'field_5ce8e1ae6558f', '12076', 'company_1399');

    The problem is, this seems destructive to other Topic terms which were set. When the field is written, it only saves this one. Others are gone.

    WordPress’ own wp_set_object_terms has an $append flag, which can be true or false, which can control whether a save is destructive or additive.

    Is there something similar I can do with ACF update_field?

    I guess ACF is always expecting an array containing the whole basket of values every time.


  • No. ACF will not use the append flag. The problem with the append flag is that if a term is removed from a taxonomy field and save/load terms is turned on that no terms will ever be removed from the relationships created by WP. This question has come up in the past. The only solution is to not use save/load terms and create your own acf/save_post filter that does a check of all the taxonomy fields involved and then add remove terms in WP yourself.

  • Okay, yes.

    I’m going to need to first check if the field contains anything…

    If it does, then I can use array_push to add another value to the array and then update_field with the completed array values.

    If not, I am free to add just the singular new value, even as a string.

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

The topic ‘update_field for Taxonomy as additive/incremental?’ is closed to new replies.