Home › Forums › Backend Issues (wp-admin) › Update field taxonomy › Reply To: Update field taxonomy
Try using the update_field
ACF API function. In my experience, the backend ACF UI wasn’t selecting the attached terms because they weren’t associated correctly in the database.
update_field documentation:
https://www.advancedcustomfields.com/resources/update_field/#usage
Here is an example that uses a Gravity Forms hook. After a user submits the form, a new post is created. Once it’s created and the terms are attached to the post, I take those terms (array) and use the update_field ACF function to attach them. Now, my taxonomy checkboxes on the backend are correctly selected.
add_action( 'gform_after_submission_1', 'update_acf_terms_for_rentals', 10, 2 );
function update_acf_terms_for_rentals( $entry, $form ) {
//get the post
$post = get_post( $entry['post_id'] );
// get the term IDs array (IDs only)
$term_list = wp_get_post_terms($post->ID, 'space', array("fields" => "ids"));
// Insert the $term_list into the database via ACF
$field_key = 'field_5b50eb94713f1';
update_field($field_key, $term_list, $post->ID);
}
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.