Home › Forums › Front-end Issues › Filing taxonomies using front-end submissions › Reply To: Filing taxonomies using front-end submissions
Hi @jack1
Could you please try to use the acf/save_post
hook instead? This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acfsave_post/.
So, your code should be something like this:
add_action('acf/save_post' , 'my_acf_save_post', 20 );
function my_acf_save_post( $post_id ) {
// only do this for application post type
if( !get_post_type($post_id) == 'application' ) return;
// initialize the post array
$post = array(
'ID' => $post_id,
);
// Some logic goes here to determine what taxonomy term the post is to be filed in
$post += ['tax_input' => array(
'taxonomy1_to_use' => $id_of_taxonomy_term1,
'taxonomy2_to_use' => $id_of_taxonomy_term2
)];
// remove the hook to avoid the infinite loop issue
// https://codex.wordpress.org/Function_Reference/wp_update_post#Caution_-_Infinite_loop
add_action('acf/save_post' , 'my_acf_save_post', 20 );
// insert the post
wp_update_post( $post );
// add the hook back
add_action('acf/save_post' , 'my_acf_save_post', 20 );
};
I hope this helps 🙂
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.