0
votes

I am using the following function to register a new custom post type on my WP site.

function new_projects() {
    $args = array(
      'label' => 'Our Projects',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'our-projects'),
        'query_var' => true,
    'show_in_menu' => 'themes.php',
        'menu_icon' => 'dashicons-awards',
    'can_export'=> false,
    'menu_position' => 100,
        'supports' => array(
        'title',
                'editor',
)
        );
    register_post_type( 'our-projects', $args );
}
add_action( 'init', 'new_projects' );

And it's registering a new custom post type named Our Projects.

Now, with that I want to auto create a post under this custom post type namely 'Our Projects' or so.

How can I execute this?

Thanks

1

1 Answers

0
votes

Use the wp_insert_post function to insert posts in the database. Add this to your code.

// Create post object
$my_post = array(
    'post_title'    => 'Our Projects',
    'post_content'  => 'This is an auto created post under Projects.',
    'post_status'   => 'publish',
    'post_type'     => 'our-projects',
);

// Insert the post into the database
wp_insert_post( $my_post );