No need for the two functions/hooks – just use the first, with the addition of:
if ( $post_id = wp_insert_post( $user_page ) ) {
wp_update_post(
array(
'ID' => $post_id,
'post_name' => $post_id,
)
);
}
Related Posts:
- wp_insert_post() getting slower the more posts
- Efficient way to save a lot of meta data
- How to use wp_insert_post to update meta box?
- wp_insert_post bulk import 500 server error
- Set default Custom Post Meta Value
- update_post_meta, xml parser
- Check if post is added manually or through wp_insert_post()
- Attaching taxonomy data to taxonomy with wp_insert_post
- Combining wp_insert_post() and update_post_meta()
- wp_insert_post inside save_post adds wrong metadata to inserted post
- Get original post ID after wp_insert_post
- Insert post programmatically and decide to tweet or not to tweet
- How to update custom fields using the wp_insert_post() function?
- Attaching taxonomy data to post with wp_insert_post
- Passing error/warning messages from a meta box to “admin_notices”
- Faster way to wp_insert_post & add_post_meta in bulk
- wordpress sanitize array?
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Is there a downside of using wp_defer_term_counting?
- wp_insert_post extremely slow on big table, direct query very fast
- What is “meta_input” parameter in wp_insert_post() used for?
- wp_insert_post add meta_input
- tax_input not working wp_insert_post
- wp set object terms vs wp set post terms
- Execute action after post is saved with all related post_meta records (data)
- update_post_meta and update_field ony working when saving the post
- See error message from wp_insert_post function?
- Create posts on user registration
- Adding post thumbnail in programatically inserted post
- can’t edit post_modified in wp_insert_post (bug?)
- advanced custom fields update_field for field type: Taxonomy
- wp_insert_post incorrectly escapes HTML comments when they include tags
- What is considered the post’s creation date for wp_insert_post?
- save_post + insert_post = infinite loop
- Insert new term during new post creation
- wp_insert_post creates multiple pages
- How to allow data:image attribute in src tag during post insert?
- tax_input argument for wp_insert_post()
- Get updated meta data after save_post hook
- Manipulating post meta in the customizer
- Add post meta based on another post meta value before publish post
- How can I stop wp_update_post messing up HTML example code?
- Better post meta efficiency?
- XMLRPC Avoid duplicate content
- How to insert custom function into wp_insert_post
- update_post_meta() not working in save_post
- How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?
- Creating a custom post type upon registration
- wp_insert_post does not write my post_name
- Is there a way to fire other functions from wp_insert_post
- Post meta checkbox becomes unchecked occasionally
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Programmatically add terms to custom post types
- Set Primary category using the Yoast SEO plugin
- Metabox of one post influence setting on other
- Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter
- wp_insert_post not returning post ID? [closed]
- wp_insert_post to schedule a post – but nothing happens?
- post_date_gmt and post_date [duplicate]
- wp_insert_post() Callback?
- Get data from wp_editor()
- Get updated post meta on save_post action?
- update_post_meta not working in save_post
- wp_insert post doesn’t work
- Replace string with post_name on sidebar
- Correct processing of `$_POST`, following WordPress Coding Standards
- update_post_meta() whenever custom post type is updated
- unable to save post meta on single field with multiple selects
- Inserting Hundreds of Thousands of Posts at Once
- Trigger “unsaved changes” dialog for custom post meta changes
- Delete post meta conditionally after save post
- Visual Editor – Colorize Shortcodes
- wp_insert_post insert a post but return 0
- How to update post parent?
- post_status => publish not working
- wp_insert_post returns int(0)
- Contact Form 7 to featured image
- Conditionally set post_content in wp_insert_post
- Is it possible to create a post using a metabox?
- wp_insert_post -> post_content not showing
- after wp_insert_post need to get the post id
- Is wp_insert_post exactly the same as publishing a post through the core UI?
- Could not get post ID from wp_insert_post()
- Creating New Page with WP_INSERT_POST Issue
- wp_insert_post is not creating revision in database
- wp_insert_post issue
- Adding custom fields (post meta) before/during wp_insert_post()
- Inserting post, thumnail and custom fields with wp_insert_post
- add_menu_page Callback Function: Skip page content?
- update post meta for checkbox in the admin when inserted in the front-end
- update_post_meta() with a modified array?
- WPML – Set language of inserted post
- Set the value of custom field when post is published or updated
- Can’t get post ID using wp_insert_post_data
- save_post action to include wp_insert_post_data filter, gathering meta field info & prevent infinite loop
- using wp_insert_post inside of custom meta box
- wp_insert_post or wp_set_post_terms do not save taxonomy, but wp_set_post_terms does
- Get Meta Key Value While Saving Post
- Making sure wp term relationships records are unique
- Pre insert data when adding new custom post fire a json error