Support

Account

Home Forums Front-end Issues Pass new $post_id to url or… Reply To: Pass new $post_id to url or…

  • Hi @synergywp

    No worries. Taking the code from the doc example, I have added the new post_id to the return data which ACF will then redirect to!

    
    <?php 
     
    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => 'A title, maybe a $_POST variable' ,
            'post_type'  => 'post' ,
        );  
     
        // insert the post
        $post_id = wp_insert_post( $post ); 
        
        
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
        
        
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
     
    ?>