Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Update post_meta post_name with the post ID from wp_insert_post after user register

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:

  1. wp_insert_post() getting slower the more posts
  2. Efficient way to save a lot of meta data
  3. How to use wp_insert_post to update meta box?
  4. wp_insert_post bulk import 500 server error
  5. Set default Custom Post Meta Value
  6. update_post_meta, xml parser
  7. Check if post is added manually or through wp_insert_post()
  8. Attaching taxonomy data to taxonomy with wp_insert_post
  9. Combining wp_insert_post() and update_post_meta()
  10. wp_insert_post inside save_post adds wrong metadata to inserted post
  11. Get original post ID after wp_insert_post
  12. Insert post programmatically and decide to tweet or not to tweet
  13. How to update custom fields using the wp_insert_post() function?
  14. Attaching taxonomy data to post with wp_insert_post
  15. Passing error/warning messages from a meta box to “admin_notices”
  16. Faster way to wp_insert_post & add_post_meta in bulk
  17. wordpress sanitize array?
  18. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  19. Is there a downside of using wp_defer_term_counting?
  20. wp_insert_post extremely slow on big table, direct query very fast
  21. What is “meta_input” parameter in wp_insert_post() used for?
  22. wp_insert_post add meta_input
  23. tax_input not working wp_insert_post
  24. wp set object terms vs wp set post terms
  25. Execute action after post is saved with all related post_meta records (data)
  26. update_post_meta and update_field ony working when saving the post
  27. See error message from wp_insert_post function?
  28. Create posts on user registration
  29. Adding post thumbnail in programatically inserted post
  30. can’t edit post_modified in wp_insert_post (bug?)
  31. advanced custom fields update_field for field type: Taxonomy
  32. wp_insert_post incorrectly escapes HTML comments when they include tags
  33. What is considered the post’s creation date for wp_insert_post?
  34. save_post + insert_post = infinite loop
  35. Insert new term during new post creation
  36. wp_insert_post creates multiple pages
  37. How to allow data:image attribute in src tag during post insert?
  38. tax_input argument for wp_insert_post()
  39. Get updated meta data after save_post hook
  40. Manipulating post meta in the customizer
  41. Add post meta based on another post meta value before publish post
  42. How can I stop wp_update_post messing up HTML example code?
  43. Better post meta efficiency?
  44. XMLRPC Avoid duplicate content
  45. How to insert custom function into wp_insert_post
  46. update_post_meta() not working in save_post
  47. How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?
  48. Creating a custom post type upon registration
  49. wp_insert_post does not write my post_name
  50. Is there a way to fire other functions from wp_insert_post
  51. Post meta checkbox becomes unchecked occasionally
  52. wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
  53. Programmatically add terms to custom post types
  54. Set Primary category using the Yoast SEO plugin
  55. Metabox of one post influence setting on other
  56. Organizing uploaded media with wp_insert_post() and wp_handle_upload according to time parameter
  57. wp_insert_post not returning post ID? [closed]
  58. wp_insert_post to schedule a post – but nothing happens?
  59. post_date_gmt and post_date [duplicate]
  60. wp_insert_post() Callback?
  61. Get data from wp_editor()
  62. Get updated post meta on save_post action?
  63. update_post_meta not working in save_post
  64. wp_insert post doesn’t work
  65. Replace string with post_name on sidebar
  66. Correct processing of `$_POST`, following WordPress Coding Standards
  67. update_post_meta() whenever custom post type is updated
  68. unable to save post meta on single field with multiple selects
  69. Inserting Hundreds of Thousands of Posts at Once
  70. Trigger “unsaved changes” dialog for custom post meta changes
  71. Delete post meta conditionally after save post
  72. Visual Editor – Colorize Shortcodes
  73. wp_insert_post insert a post but return 0
  74. How to update post parent?
  75. post_status => publish not working
  76. wp_insert_post returns int(0)
  77. Contact Form 7 to featured image
  78. Conditionally set post_content in wp_insert_post
  79. Is it possible to create a post using a metabox?
  80. wp_insert_post -> post_content not showing
  81. after wp_insert_post need to get the post id
  82. Is wp_insert_post exactly the same as publishing a post through the core UI?
  83. Could not get post ID from wp_insert_post()
  84. Creating New Page with WP_INSERT_POST Issue
  85. wp_insert_post is not creating revision in database
  86. wp_insert_post issue
  87. Adding custom fields (post meta) before/during wp_insert_post()
  88. Inserting post, thumnail and custom fields with wp_insert_post
  89. add_menu_page Callback Function: Skip page content?
  90. update post meta for checkbox in the admin when inserted in the front-end
  91. update_post_meta() with a modified array?
  92. WPML – Set language of inserted post
  93. Set the value of custom field when post is published or updated
  94. Can’t get post ID using wp_insert_post_data
  95. save_post action to include wp_insert_post_data filter, gathering meta field info & prevent infinite loop
  96. using wp_insert_post inside of custom meta box
  97. wp_insert_post or wp_set_post_terms do not save taxonomy, but wp_set_post_terms does
  98. Get Meta Key Value While Saving Post
  99. Making sure wp term relationships records are unique
  100. Pre insert data when adding new custom post fire a json error
Categories wp-insert-post Tags post-meta, save-post, user-registration, wp-insert-post
WordPress Payment link will not transform PHP vars into values
How to markup wordpress site using Schema.org?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress