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. What does this PHP function code mean? [closed]
  10. Query all posts where a meta key does not exist
  11. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  12. what is the correct way to compare dates in a WP query_posts meta_query
  13. Advanced search form with filters for custom taxonomies and custom fields
  14. Meta query with boolean true/false value
  15. Get post with multiple meta keys and value
  16. Correctly delete posts with meta and attachments [duplicate]
  17. Storing revisions of metadata for custom post type
  18. Custom field values deleted when trashing custom post type
  19. How to get all custom fields of any post type
  20. Update CPT meta data using REST API
  21. Admin Area Custom Type Search By Meta Fields Without Title & Content
  22. Echo all meta keys of a custom-post TYPE
  23. Custom Post type – how to get checkbox to update meta field to null
  24. How can I filter posts by post_parent in the admin?
  25. How do I Paginate Search Results for Custom Post Types?
  26. Ordering posts having multiple post-meta date fields
  27. Custom meta box data not saving
  28. custom search results – order results differently by post type
  29. update a posts of other custom post type
  30. How do I extract the contents of a CPT’s custom field for all posts?
  31. Stripe multiple transactions
  32. How do i create user accounts from custom posts that have email addresses
  33. Collect custom post in a calendar
  34. Storing data in a multidimensional array from dynamically generated foreach loop
  35. How to get Current week and current date record wp query
  36. How to get post meta for custom post type and taxonomy
  37. get_post_meta for Custom Post Type ( CPT )
  38. Creating multiple profiles under one user to assign to particular posts
  39. Delete custom post type metadata without deleting the post in admin area
  40. Edit is changing my custom’s post type parent id
  41. Order by post meta value gets random results
  42. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  43. Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
  44. Disable Facebook Comments Automatically On CPT
  45. How to add post reference field to a plugin?
  46. meta query always fails even if data is correct
  47. Problem with ‘save_post’ hook not running
  48. WordPress custom post type
  49. Custom Post Type with /%shop_name%/gallery/%gallery% permastruct?
  50. Would like to add a “leaderboard” (custom field) to a custom post type
  51. Edit post meta direct from post.php?
  52. Howto: use existing post_meta as options for a different metabox (checkboxes or list)
  53. predefined custom field on registration page
  54. Custom Post Type meta oembed html output resulting in WSoD
  55. Values inside a custom field to determine which category posts to display
  56. How to create content automatically when a post is published?
  57. Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
  58. Multisite – Echo admins profile meta
  59. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  60. Rich Custom Field for Custom Post type not saving
  61. Add auto increment value to custom meta
  62. Custom post type submenu sorted by specific meta_key & meta_value
  63. Updating User Meta from Custom Post Field Upon Publish Not Working
  64. Display and Allow users to edit their own profiles
  65. Return only custom post types for the page, not all
  66. Change the contents of a dropdown through the admin panel?
  67. Advanced search form with filters for custom taxonomies and custom fields
  68. Retrieve post data via WPDB class
  69. Top 30 Songs using Custom Post Type
  70. Advice Needed for Post Meta Database Efficiency
  71. fetch meta fields inside a widget
  72. Querying meta values within an array
  73. Create action running on trashed_post hook to modify post_meta value
  74. Post AND page parameter for WP function
  75. Random meta field from specific custom post type
  76. Custom post type – update_meta not working
  77. Trying to display posts by authors in with specific user meta
  78. why get_post_meta is returning 0?
  79. Custom Post Type meta value is being saved in array, instead of just the string (as value)
  80. Save post_parent in a custom post type
  81. Custom Form Data save after Login User
  82. Use a Variable in update_post_meta as the $meta_key
  83. Save multiple checkboxes with Types
  84. Automatically add custom taxonomy when meta value gets to a set number or beyond
  85. How can I get user URL by id
  86. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  87. Update an existing post in a custom post type
  88. Check for custom field value in different post type than current one and do something
  89. Changing to different post type maintains the redirection?
  90. Post Meta for Custom Post Types
  91. How do I add the “orange counter” next to a Custom Post Type?
  92. getEntityRecords/useEntityRecords: How to use CPT metadata?
  93. I am having a problem with fetching product data in the Gutenberg block editor
  94. CPT meta values intermittently return empty
  95. Quering a post object based on another related post object
  96. rest_api_init is not getting invoked inside a Class
  97. Need some suggestions with Relationship fields and CPT/ACF
  98. Normal Posts and Custom Posts with Date Query
  99. Optimizing storage of Post Meta Entries
  100. Allowing a CPT post to be edited by a single user role
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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