I want to have a menu item that will, on-click, add a page with certain arguments.
In it’s simplicity, I have:
function av_subscribe_create_menu(){
// Create top-level menu
add_menu_page( 'Add Comment Feed', 'Add Comment Feed', 'manage_options', __FILE__,
'av_subscribe_create_feed_page', '' );
}
add_action( 'admin_menu', 'av_subscribe_create_menu' );
function av_subscribe_create_feed_page(){
$page = array(
'post_type' => 'page',
'post_status' => 'publish',
'post_parent' => 13570
);
$new_page_id = wp_insert_post($page, false);
}
This doesn’t work and even if it did, I don’t believe it would take me to the Edit screen. Is there a way you can use a function to add a post and go directly to the edit screen?
Also, bonus question: If you do not specify a title, but you specify the post_status as publish, will this automatically create a slug for you? I don’t want an auto-generated slug of some gibberish. Thanks in advance.
It certainly will! Check the source code for
wp_insert_post()
.