Support

Account

Home Forums Backend Issues (wp-admin) my_acf_update_value breaking default save

Solved

my_acf_update_value breaking default save

  • Hello,

    I’m trying using my_acf_update_value in conjunction with a Custom Post Type taxonomy. I’m using the following:

    function my_acf_update_value( $value, $post_id, $field  ) {
      $id = str_replace('filter_', '', $post_id);
      wp_update_term($id, 'filter', array(
        'term_group' => $value
      ));
      return $value;
    }
    add_filter('acf/update_value/name=filter_order', 'my_acf_update_value', 10, 3);

    On save I set the ‘term_group’ for the taxonomy to that of the acf value so that I can use it for sorting purposes with ‘get_terms()’

    Unfortunately I’ve found a bug where when Editing a taxonomy if I try to change one of the default fields, ie the “Name” or “slug” and hit save, it doesn’t update. The only thing that updates from that page is the ACF field.

    The only workaround is using the “quick edit” tool. It’s the weirdest thing.

    I have confirmed that when I comment out this hook, that it works fine on save.

  • Ok I think I figured it out:

    It’s not ACF breaking it, though it’s related. ‘wp_update_term’ if you don’t specify a value for an argument it uses the default. So my guess is it’s grabbing what’s in the database already and overriding what you’ve specified in the form.

    A work-around, is instead of using the ‘wp_update_term’ function is to just do:

      global $wpdb;
      $wpdb->update($wpdb->terms, array('term_group' => $value), array('term_id'=>$term_id));
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘my_acf_update_value breaking default save’ is closed to new replies.