Support

Account

Home Forums General Issues pre_save_post using \'import_id\' Reply To: pre_save_post using \'import_id\'

  • This is the code that works for me. Note the $GLOBALS['acf_form']['return']

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' ) {
            return $post_id;
        };
    
        $title = trim($_POST['acf']['field_5702e3df3ce82']);
    
        // Create a new post
        $post = array(
            'post_status'  => 'publish' ,
            'import_id' => $_POST['acf']['field_5702b6a15e788'],
          	'post_title' => $title,
          	'post_name' => sanitize_title( $title ),
            'post_type'  => 'app'
        );
    
        // insert the post
        $post_id = wp_insert_post( $post );
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $GLOBALS['acf_form']['return'] );
    
        // return the new ID
        return $post_id;
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post');