Home › Forums › General Issues › priority issue with function › Reply To: priority issue with function
It seems odd to me that the terms are being removed from a post when you change the post title. I’ve actually done this on several projects and I’ve never had a problem having it run on acf/save_post with a priority of 20. This makes me think that there may be other filters running on the site that are causing some type of interference.
Looking at your code again I have a one suggestion, but I’m not sure it’ll change anything.
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
$posttypes = array( 'post', 'portfolio', 'recensies', 'page' );
// specify post id in get_post_type
$currentposttype = get_post_type($post_id);
if ( in_array( $currentposttype, $posttypes ) ) { //only run if is certain post-type
if( $currentposttype == 'post' || $currentposttype === 'portfolio' || $currentposttype === 'page' ) {
$my_post['post_title'] = $_POST['acf']['field_56df22028f627'];
} elseif( $currentposttype === 'recensies') {
$my_post['post_title'] = $_POST['acf']['field_56dee620f84d5'] . ' (' . $_POST['acf']['field_56dee62cf84d6'] . ') - ' . $_POST['acf']['field_5734c3bcceb6c'];
}
//Unhook function to prevent infitnite looping
remove_filter('acf/save_post', 'my_post_title_updater', 1);
// 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', 1);
}
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 1);
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.