How to crteate a custom post type page with content via plugin activation

I’m converting a php script to function as a WP plugin. One of the things I need to accomplish is to have front facing forms to collect information. I’ve found how to create new pages when a plugin is activated and how to add blocks. I also know how to create custom post types.

I need to combine elements of the two operations so that I can create say category pages (a) teachers, (b) students, (c) events, (d) xyz. Why do I need custom types? If I create the pages and make them available on the front to collect new teacher, student records etc on the front, that’d be fine. However, (1) I need to be able to “create new teacher” etc on the back-end as well and (2) I need to have organized searchable archives.

This gives me my single page:

    $page = array(
      'post_title'  => __( 'New Page' ),
      'post_status' => 'publish',
      'post_content'   => '[content-shortcode]',
      'post_author' => $current_user->ID,
      'post_type'   => 'page',
      'comment_status' => 'closed',
      'ping_status' =>  'closed' ,
    wp_insert_post( $page );

Does the same snippet offer the creation of a post_type’ => ‘post’ and to also add post_content? I’m not quite clear from what I’ve read.

Source link