Can someone explain to me what might be happening? Or maybe I’m just misunderstanding the documentation for the Taxonomy field. I’m seeing two issues, one with the “Save Terms” option and the other with “Load Terms”. For context, I have a repeater field with one of the subfields as a taxonomy field set to use the default post tags taxonomy.
When I set the “Save Terms” to true with the intention to make it so whatever tag they set here is also assigned to the post in the sidebar, making it dummy-proof for my editors in case they forget to also assign the tag to the post. But doing so while editing a post wipes out all other tags upon saving and makes it so that the tag assigned in this ACF subfield is the _only_ tag assigned to the post. Obviously this is not what I want, and I just set it to false and hope that my editors remember to assign the same tag they selected in ACF to the actual post.
As an alternative to the first issue, my second issue is when I set “Load Terms” to true with the idea that _only_ the tags assigned to the post will appear in the drop down, so it forces the editors to assign it first and then use the ACF. However, all tags appear in the drop-down, regardless if any tags are assigned to the post. Even worse, if I have two tags assigned to my post and I use field to point to the second one, after saving, it forcefully points to the first tag. Once again, I set this ACF configuration to false so it at least behaves normally but now I can’t really dummy-proof it for my editors in any capacity.
Is this the intended behavior of “Save Terms” and “Load Terms” or is something going on? Thanks in advance!
The behavior you’re seeing is what will happen. Taxonomy fields with save/load terms cannot really be used as sub fields of a repeater.
For save terms, as each row is updates wp_set_post_terms() is called. This has the effect of deleting any current terms and setting the new ones.
For load terms it will only load the terms set in the last field update.
This can be an issue and it is not covered in the documentation. Because of the way ACF works the taxonomy field cannot know what happened the last time the value was saved. This same behavior can be seen if you create 2 top level taxonomy fields that pull terms from the same taxonomy. Basically what this means is that any post can only have a single occurrence of a taxonomy field for any taxonomy if you want to use save/load terms.
If you want to have save/load terms in a repeater (or flex field) you need turn these settings off. You must build an acf/save_post action. In this action you need to loop over the repeater, get all of the terms from all rows and then call wp_set_post_terms() yourself including the entire list of terms to be set.
Thank you for your swift reply!
It’s unfortunate that the taxonomy field is not modular in the way I expected it to be since it would’ve made sense for the fields to function in the way I expected. Eespecially since how the documentation was worded, there wasn’t any reason for me to believe it wouldn’t work.
Thank you! I’ll consider building an acf/save_post action after a think about the effort/reward levels. It might just be something I include in the documentation for the editors and if they wonder why something isn’t showing up, then they’ll email me lol
You must be logged in to reply to this topic.
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!
© 2020 Advanced Custom Fields. Subscribe