Support

Account

Home Forums General Issues how to assemble different post_type types Reply To: how to assemble different post_type types

  • Hello
    thank you for the answer

    so if i understand correctly the code i showed you is not good. so i have to replace
    this code

    <?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'  => 'peche' ,
        );  
    
        // insert the post
        $post_id = wp_insert_post( $post ); 
    
        // return the new ID
        return $post_id;
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
    
    ?>
    
    

    by this one

    
    // only relevant arguments are included
    $args = array(
      'post_id' => 'new_post',
      'new_post' => array(
        'post_type' => 'peche',
        'post_status' => 'draft',
        'post_title' => $_POST['acf']['field_XXXXXXX'] // the field key you want to use for title
      }
    );