Home › Forums › General Issues › Taxonomy field option Save Terms prevents the default category from saving › Reply To: Taxonomy field option Save Terms prevents the default category from saving
The problem is that ACF uses wp_set_object_terms() to update the terms. This happens after WP has already saved the post. ACF does not look to see if the post already has terms set for a taxonomy before doing the update. You might consider submitting a new support ticket, this could be considered a bug, but the developer might not https://support.advancedcustomfields.com/new-ticket/.
But the default value is generally only used if no category is selected, or do you mean that this is the case?
Using filters and hooks available in ACF it would be possible to work around this issue. You can use an acf/update_value filter https://www.advancedcustomfields.com/resources/acfupdate_value/ to add the default term to the value array before it is updated
add_filter('acf/update_value/name=field_name', 'set_default_category', 9, 3);
function set_default_category($value, $post_id, $field) {
if (!is_array($value) || !count($value) {
$value = array(1); // 1 = Uncategorized
}
return $value;
}
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.