Support

Account

Home Forums General Issues Adding taxonomies to attachments Reply To: Adding taxonomies to attachments

  • ACF stores the values of a taxonomy field as an array of term ID values.

    So you’ve basically got to get the current category, split it on the commas and then get the correct term ID and put them in an array. See get_term_by() https://codex.wordpress.org/Function_Reference/get_term_by

    
    $list = split(',', $current_category);
    $categories = array();
    foreach ($list as $name) {
      $term = get_term_by('name', $name, $your_taxonomy);
      $categories[] = $term->term_id;
    }
    update_field($fieldKey, $categories, $attachmentID);