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:
- Creating a custom post type upon registration
- how to delete all users and posts based on ‘user_meta’?
- Restrict Access to Posts based on Custom User and Post Meta Data
- Meta box with front-end styling
- Create WordPress User in backend, and automatically create a new post in Custom Post Type with user uame as the Title in the post
- UPDATED: Save a custom_field value when automatically creating a post using wp_insert_post
- Display a post count from a custom metabox selection
- How to display Author Profile based on Custom field value
- Correctly delete posts with meta and attachments [duplicate]
- Storing revisions of metadata for custom post type
- Ordering posts having multiple post-meta date fields
- Custom Post Type with Input fields to seperate table on database.
- How Can I save multiple records in same meta key?
- Permalinks using event date (year & month) instead of publication date
- How to create user personal pages with information from their meta profile fields?
- Reason action hook won’t work with update_post_meta from frontend form? Alternative?
- Showing Meta Data for Custom Post Types?
- Having trouble with custom post type / meta box
- Query for posts from any post type but only add instock products
- update custom post type meta from a shortcode
- How to keep a check box in custom meta box for custom post type checked by default for add new post?
- Show metabox in custom-post-template depending on taxonomy term?
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Want to turn WordPress into a paid subscription directory
- Using date stored as custom field to filter posts displayed in admin
- Meta Box Only in CPT Edit Page, Not in Add New
- get_template_part() – post-meta not working?
- Does WordPress limit the length of slug names for Post Meta or Terms?
- Populate Custom Fields in a Custom Post Type?
- Insert Multiple Post with Same Publish Button
- Custom meta box data array: foreach not working correctly?
- Undefined Variable – Custom Post Type Meta
- How to check if user meta field is empty in conditional else statement
- Post image in WordPress not appearing on home page
- Team club with CPTs and user registration + user dashboard
- Getting meta in editor plugin, and event triggering issue
- Should wp_postmeta meta_key always be unique for a given post_id?
- Metabox not show in categories custom post type cmb2
- Users create/join groups
- Importing Data from a Non-WordPress database, into WP
- List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Filter date from post meta when date is in string format
- Get $post->ID from a URL
- Displaying a div from an assigned meta_value when on a page
- Setting Post Title via Meta Data returns Auto-draft
- Values from meta-box not on $_POST
- Returning a custom content types with meta values
- How do I create a new post upon registration with the users first and last name as title
- Custom post type suddenly stoped working after WordPress 5 update
- How to show custom field on specific custom post type posts only when filled
- is_main_query() never called on WP 4.4
- How can I output WPAlchemy repeating fields meta values in my page template?
- Meta box data not saving
- Related posts meta_query CPT
- How can I get some of a posts meta data whilst it is still inserting?
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Cannot Save MetaBox Data in Custom Post Type
- best way to use custom taxonomy, post type and meta in a job system
- Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
- How to order custom posts by one of the custom fields value, ‘date’?
- Hide title field of selected post-types on edit pages
- WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- How to create review point system for CPTs (many-to-many relationship)
- 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
- How can I write a function that would update any missing specific post metadata?
- SELECT custom post type and its meta in SQL
- Conditional editing CPT – using editor’s role and author’s usermeta
- How to keep custom post type related information
- Custom attachment function not working in v5.4.2?
- Can’t save meta box data in WordPress using custom post types
- How to sort by multiple values in a nested WP_Query
- Where is get_post_meta value located?
- How can I use a custom template to load custom post type posts based on a post_meta value
- How do I create a customised table list of a custom post type (in the admin area)?
- How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
- How to save post_status using action save_post?
- Custom post meta box as a sub form
- Metaboxes in Loop
- Custom meta box data not saving
- Collect custom post in a calendar
- How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
- meta query always fails even if data is correct
- Would like to add a “leaderboard” (custom field) to a custom post type
- Values inside a custom field to determine which category posts to display
- Multisite – Echo admins profile meta
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- Custom post type submenu sorted by specific meta_key & meta_value
- Display and Allow users to edit their own profiles
- Advanced search form with filters for custom taxonomies and custom fields
- Querying meta values within an array
- Post AND page parameter for WP function
- why get_post_meta is returning 0?
- Save post_parent in a custom post type
- Automatically add custom taxonomy when meta value gets to a set number or beyond
- How can I get user URL by id
- Display a list of posts whose meta field values are equal to the ID of the post being viewed?
- Check for custom field value in different post type than current one and do something
- I am having a problem with fetching product data in the Gutenberg block editor