Home › Forums › General Issues › Update Taxonomy of posts selected by acf relation field › Reply To: Update Taxonomy of posts selected by acf relation field
Is list the name of your taxonomy? That’s about the only thing I think will cause an issue.
This line should be limiting your the adding of terms to only things that have the values set
if( $PostList ):
The post ID passed to your function for a term would be something like “term_100” where 100 will be the id of the term. You need to extract this.
$term_id = intval(str_replace('term_', $post_id));
and now that I’m looking at it the order of your arguments are also wrong.
$posts = get_field('downloads_listing', $post_id);
$term_id = intval(str_replace('term_', $post_id));
if ($posts) {
foreach ($posts as $post) {
// make sure "list" is the taxonomy name and not the term name
wp_set_post_terms($post->ID, $term_id, 'list', true);
}
}
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.