Home › Forums › Backend Issues (wp-admin) › Use ACF/Save Post Action to update a Custom Taxonomy › Reply To: Use ACF/Save Post Action to update a Custom Taxonomy
yes I did, here is the code I am using.
function change_post_taxonomy_44582( $post_id ) {
if ( empty($_POST['acf']) ) {
return;
}
// get term id from $post_id (only 1 value is allowed, so it returns 1 value only)
$stored_role = wp_get_post_terms($post_id, 'asproducts_cats');
// get submitted value from acf form
$posted_roles = $_POST['acf']['field_59154e83efb0e'];
// get term_id for the submitted value
$term_id = get_term_by( 'name', $posted_roles, 'asproducts_cats' );
// if stored value is not equal to posted value, then update terms
if ( $stored_role[0] != $posted_roles ) {
wp_set_object_terms( $post_id, $term_id->term_id, 'asproducts_cats' );
}
}
add_action('acf/save_post', 'change_post_taxonomy_44582', 20);
Also have a look here https://support.advancedcustomfields.com/forums/topic/conditional-logic-using-taxonomy-field/page/4/
A nice chap helped me out with this. Shout if you are still having issues
Keith
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 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.