Support

Account

Home Forums Add-ons Repeater Field Taxonomy field inside a repeater not saving properly? Reply To: Taxonomy field inside a repeater not saving properly?

  • It’s not really a bug, the taxonomy field in one row of a repeater does not know what’s going on with the same field in another row. It would be possible to “append” values, but then there is the issue with “removing” values first. For example, in you changed the selected term in a row and ACF used the append terms version of the function then the term you wanted to remove would still be there. ACF solves this by replacing all the terms whenever it updates a taxonomy field.

    At any rate, I would to something along the lines of this after change the field to not load or set terms. But you should be aware that you will not be able to set these taxonomy/terms anywhere but in the ACF field.

    
    add_action('acf/save_post', 'update_repeater_post_terms');
    function update_repeater_post_terms($post_id) {
      if (get_post_type($post_id) != 'YOUR POST TYPE HERE') {
        return;
      }
      $terms = NULL; // this will clear terms if none found
      if (have_rows('YOUR REPEATER', $post_id)) {
        $terms = array();
        while (have_rows('YOUR REPEATER', $post_id)) {
          // add this term to the array
          $terms[] = get_sub_field('YOUR SUB FIELD', false); // false for no formatting
        }
      }
      set_object_terms($post_id, $terms, 'YOUR TAXONOMY HERE', false);
    }