Support

Account

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;
    }