And once again I answer myself 😉
I forgot the $post_id
inside the acf-field. This is how it works perfectly:
function update_post_taxonomy( $post_id ) {
$myfield = get_field('my_field_name', $post_id);
if( $myfield ) {
wp_set_object_terms($post_id, 'myterm', 'mytaxonomy', true);
} else if ( empty( $myfield ) ) {
wp_remove_object_terms( $post_id, 'myterm', 'mytaxonomy', true );
}
}
add_action( 'acf/save_post', 'update_post_taxonomy', 10 );
Thank you @hube2 , that’s completely true!
In the meantime I found a solution that works for me. If anyone else needs it:
function update_post_taxonomy( $post_id ) {
$myfield = get_field('my_field_name');
if( $myfield ) {
wp_set_object_terms($post_id, 'myterm', 'mytaxonomy', true);
}
add_action('acf/save_post', 'update_post_taxonomy', 20);
Cheers!
Thank you for your quick solution, but unfortunately it doesn’t work. I tested it in various ways. In addition, there is no need for a new approach here, just an example of a mapping of multiple checkboxes from Gravity to ACF like in Franck’s code above, which works wonderfully.
I have 9 multiple checkbox fields in Gravity that I want to map to 9 multiple checkbox fields in ACF. If anyone could help with this, that would be great! 😊
Yes, I need a solution here too. It would be great if someone could show a solution for this. Thanks in advance!
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.