Home › Forums › General Issues › Update Taxonomy of posts selected by acf relation field › Reply To: Update Taxonomy of posts selected by acf relation field
There is an error in my code I gave you
This line should be causing an error in php
$term_id = intval(str_replace('term_', $post_id));
it should be
$term_id = intval(str_replace('term_', '', $post_id));
I also set up a test using posts and categories, this is working as expected
add_filter('acf/save_post', 'category_list_save', 20, 1);
function category_list_save($post_id) {
$posts = get_field('posts', $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, 'category', true);
}
}
}
It it’s still not working for you make sure that your taxonomy and post type are attached. https://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type
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.