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);
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.