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);