I know that I can programmatically create a new page via wp_insert_post setting ‘post-type’ to ‘page.’
How do I go about editing that page programmatically? (title, content, slug, etc.)
Also, if I wanted to set the template for that page programmatically, how would I do that?
If you look at the documentation, you can insert title, content, slug, etc. using wp_insert_post
then use update_post_meta
to assign the template to that post.
You can write like this
$post_arr = array(
'post_title'=>'My title goes here',
'post_content'=>'This is my long content.',
'post_excerpt' => 'My Excerpt',
'post_status' => 'publish',
);
$new_post_id = wp_insert_post($post_arr);
Then set template like this.
update_post_meta( $new_post_id, '_wp_page_template', 'template-file.php' );
To see more options for wp_insert_post
, you can check it’s documentation page.