Home › Forums › Feature Requests › Conditional Logic using Taxonomy field › Reply To: Conditional Logic using Taxonomy field
Bee, I’v found plugin https://github.com/mattkeys/ACF-Conditional-Taxonomy-Rules it works with multiple select fields, it works!
Pleace help with your code?
I’ve chanched filed name and taxonomy name to save by wp, but it is not work, what is wrong?
function change_post_taxonomy_44582( $post_id ) {
// bail if no ACF data
if ( empty($_POST['acf']) ) {
return;
}
// get term id from $post_id (only 1 value is allowed, so it returns 1 value only)
$stored_sex = wp_get_post_terms($post_id, 'aptype');
// get submitted value from acf form
$posted_sex = $_POST['acf']['acf-field_5c72c3e3cfc4d'];
// get term_id for the submitted value
$term_id = get_term_by( 'name', $posted_sex, 'aptype' );
// if stored value is not equal to posted value, then update terms
if ( $stored_sex != $posted_sex ) {
wp_set_object_terms( $post_id, $term_id->term_id, 'aptype' );
}
}
add_action('acf/save_post', 'change_post_taxonomy_44582', 20);
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.