Home › Forums › General Issues › Okay, why are my custom taxonomies not saving anymore
Hi guys!
Why are my custom taxonomies not saving to my cpt’s anymore? the terms are loaded but not saved to the post.
How could this have happened at once?
Im building a pretty big community website and this is not acceptable if you ask me and brings me in trouble.
Let me know what you’d need to know.
Is this on admin forms or front end forms? I’ve tried with both and everything seems to be working.
Have you tried all the usual suspects, deactivating other plugins, trying another theme, etc?
Could this have something to do with the taxonomy term split? Are the terms that are not saving properly named the same as terms in some other taxonomy like tags or categories?
Hi John,
Thanks for jumping in again!
I did some more debugging (should have done this more thorough before asking questions) and found out that this function is causing the issue (the one we resolved last time! remember?
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
if ( get_post_type() == 'fotoslider' || get_post_type() == 'diensten' || get_post_type() == 'portfolio' || get_post_type() == 'partners') {
$my_post['post_title'] = get_field('kop');
}
//Unhook function to prevent infitnite looping
remove_filter('acf/save_post', 'my_post_title_updater', 20);
// Update the post into the database
wp_update_post( $my_post );
//Rehook function to prevent infitnite looping
add_filter('acf/save_post', 'my_post_title_updater', 20, 3);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 20);
any clue on why it is causing the terms not to sync?
Thanks!
It looks familiar.
I don’t see anything there that should cause terms not to be saved properly. I really like the way hooks work most of the time but there are other times they just create a mess. Let me think about it.
So if you remove this action everything works fine?
You’re right John! If I comment the function out, the whole sync works like it should…..
Thanks for picking your brain on this!
But it shouldn’t be, which is why I’m confused, unless there is something more going on, like updating a post that shouldn’t be updated.
What if you did something like:
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
$post_types = array(
'fotoslider',
'diensten',
'portfolio',
'partners'
);
$post_type = get_post_type($post_id);
if (!in_array($post_type, $post_types)) {
// don't do anything
// if this is not one
// of the post types
// we want to change
return;
}
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_title'] = get_field('kop');
//Unhook function to prevent infitnite looping
remove_filter('acf/save_post', 'my_post_title_updater', 20);
// Update the post into the database
wp_update_post( $my_post );
//Rehook function to prevent infitnite looping
add_filter('acf/save_post', 'my_post_title_updater', 20, 3);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 20);
True!
Unfortunately it does not work either with your edited function.
One more detail, it loads the terms correctly to the ACF tax field, just not the other way – it does not update the terms with the acf field values
Maybe this is a bug that’s recently cropped up on front end forms, but I tend not to think that because you say it works fine when you remove this functions.
The only thing that I can think of now is that the call to wp_update_post() is triggering hooks that are somehow causing this issue.
Have you tried opening a support ticket http://support.advancedcustomfields.com/new-ticket/
Hi John,
I opened a ticket a while ago and still have no answer from them. any clues?
I’m not associated with the support ticket system. I just know that it’s a more direct route to the developer or those that can better help with direct support. Unfortunately, since I cannot recreate the problem that you’re having I can’t really help you. There really isn’t anything in the function you posted above that should keep a taxonomy field from saving on a front end acf_form.
The topic ‘Okay, why are my custom taxonomies not saving anymore’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.