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

Creating a custom post type upon registration for a specific user role

Try below code:

add_action( 'user_register', 'create_new_post_onuser_registration', 10, 1 );
function create_new_post_onuser_registration( $user_id ){
    // Get user info
    $user_meta = get_userdata( $user_id );

    $user_roles = $user_meta->roles;

    // Update the role here
    if ( in_array( 'subscriber', $user_roles ) ) {
        // Do something.

        // Create a new post
        $subscriber_post = array(
            'post_title'   => $user_meta->nickname;
            'post_content' => $user_meta->description,
            'post_type'    => 'custom_post_type', // Update to your custom post type
        );

        $post_id = wp_insert_post( $subscriber_post );

        // Add custom data
        add_post_meta( $post_id, 'user_email', $user_meta->user_email );
    }    
}

Related Posts:

  1. Creating a custom post type upon registration
  2. how to delete all users and posts based on ‘user_meta’?
  3. Restrict Access to Posts based on Custom User and Post Meta Data
  4. Meta box with front-end styling
  5. Create WordPress User in backend, and automatically create a new post in Custom Post Type with user uame as the Title in the post
  6. UPDATED: Save a custom_field value when automatically creating a post using wp_insert_post
  7. Display a post count from a custom metabox selection
  8. How to display Author Profile based on Custom field value
  9. Correctly delete posts with meta and attachments [duplicate]
  10. Storing revisions of metadata for custom post type
  11. Ordering posts having multiple post-meta date fields
  12. Custom Post Type with Input fields to seperate table on database.
  13. How Can I save multiple records in same meta key?
  14. Permalinks using event date (year & month) instead of publication date
  15. How to create user personal pages with information from their meta profile fields?
  16. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  17. Showing Meta Data for Custom Post Types?
  18. Having trouble with custom post type / meta box
  19. Query for posts from any post type but only add instock products
  20. update custom post type meta from a shortcode
  21. How to keep a check box in custom meta box for custom post type checked by default for add new post?
  22. Show metabox in custom-post-template depending on taxonomy term?
  23. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  24. Want to turn WordPress into a paid subscription directory
  25. Using date stored as custom field to filter posts displayed in admin
  26. Meta Box Only in CPT Edit Page, Not in Add New
  27. get_template_part() – post-meta not working?
  28. Does WordPress limit the length of slug names for Post Meta or Terms?
  29. Populate Custom Fields in a Custom Post Type?
  30. Insert Multiple Post with Same Publish Button
  31. Custom meta box data array: foreach not working correctly?
  32. Undefined Variable – Custom Post Type Meta
  33. How to check if user meta field is empty in conditional else statement
  34. Post image in WordPress not appearing on home page
  35. Team club with CPTs and user registration + user dashboard
  36. Getting meta in editor plugin, and event triggering issue
  37. Should wp_postmeta meta_key always be unique for a given post_id?
  38. Metabox not show in categories custom post type cmb2
  39. Users create/join groups
  40. Importing Data from a Non-WordPress database, into WP
  41. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  42. Can’t publish custom post type – “You are not allowed to edit this post.”
  43. Filter date from post meta when date is in string format
  44. Get $post->ID from a URL
  45. Displaying a div from an assigned meta_value when on a page
  46. Setting Post Title via Meta Data returns Auto-draft
  47. Values from meta-box not on $_POST
  48. Returning a custom content types with meta values
  49. How do I create a new post upon registration with the users first and last name as title
  50. Custom post type suddenly stoped working after WordPress 5 update
  51. How to show custom field on specific custom post type posts only when filled
  52. is_main_query() never called on WP 4.4
  53. How can I output WPAlchemy repeating fields meta values in my page template?
  54. Meta box data not saving
  55. Related posts meta_query CPT
  56. How can I get some of a posts meta data whilst it is still inserting?
  57. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  58. Cannot Save MetaBox Data in Custom Post Type
  59. best way to use custom taxonomy, post type and meta in a job system
  60. Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
  61. How to order custom posts by one of the custom fields value, ‘date’?
  62. Hide title field of selected post-types on edit pages
  63. WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
  64. Custom Post Type meta data getting deleted on bulk editing taxonomies
  65. How to create review point system for CPTs (many-to-many relationship)
  66. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  67. How can I write a function that would update any missing specific post metadata?
  68. SELECT custom post type and its meta in SQL
  69. Conditional editing CPT – using editor’s role and author’s usermeta
  70. How to keep custom post type related information
  71. Custom attachment function not working in v5.4.2?
  72. Can’t save meta box data in WordPress using custom post types
  73. How to sort by multiple values in a nested WP_Query
  74. Where is get_post_meta value located?
  75. How can I use a custom template to load custom post type posts based on a post_meta value
  76. How do I create a customised table list of a custom post type (in the admin area)?
  77. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  78. How to save post_status using action save_post?
  79. Custom post meta box as a sub form
  80. Metaboxes in Loop
  81. Custom meta box data not saving
  82. Collect custom post in a calendar
  83. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  84. meta query always fails even if data is correct
  85. Would like to add a “leaderboard” (custom field) to a custom post type
  86. Values inside a custom field to determine which category posts to display
  87. Multisite – Echo admins profile meta
  88. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  89. Custom post type submenu sorted by specific meta_key & meta_value
  90. Display and Allow users to edit their own profiles
  91. Advanced search form with filters for custom taxonomies and custom fields
  92. Querying meta values within an array
  93. Post AND page parameter for WP function
  94. why get_post_meta is returning 0?
  95. Save post_parent in a custom post type
  96. Automatically add custom taxonomy when meta value gets to a set number or beyond
  97. How can I get user URL by id
  98. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  99. Check for custom field value in different post type than current one and do something
  100. I am having a problem with fetching product data in the Gutenberg block editor
Categories custom-post-types Tags custom-post-types, post-meta, user-meta, user-registration
How to insert multiple rows and columns in database using array
Why do I have a reauth=1 redirection loop when I try to log in to WordPress hosted on AWS Fargate?

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