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
- What does this PHP function code mean? [closed]
- Query all posts where a meta key does not exist
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- what is the correct way to compare dates in a WP query_posts meta_query
- Advanced search form with filters for custom taxonomies and custom fields
- Meta query with boolean true/false value
- Get post with multiple meta keys and value
- Correctly delete posts with meta and attachments [duplicate]
- Storing revisions of metadata for custom post type
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Update CPT meta data using REST API
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Echo all meta keys of a custom-post TYPE
- Custom Post type – how to get checkbox to update meta field to null
- How can I filter posts by post_parent in the admin?
- How do I Paginate Search Results for Custom Post Types?
- Ordering posts having multiple post-meta date fields
- Custom meta box data not saving
- custom search results – order results differently by post type
- update a posts of other custom post type
- How do I extract the contents of a CPT’s custom field for all posts?
- Stripe multiple transactions
- How do i create user accounts from custom posts that have email addresses
- Collect custom post in a calendar
- Storing data in a multidimensional array from dynamically generated foreach loop
- How to get Current week and current date record wp query
- How to get post meta for custom post type and taxonomy
- get_post_meta for Custom Post Type ( CPT )
- Creating multiple profiles under one user to assign to particular posts
- Delete custom post type metadata without deleting the post in admin area
- Edit is changing my custom’s post type parent id
- Order by post meta value gets random results
- How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- Disable Facebook Comments Automatically On CPT
- How to add post reference field to a plugin?
- meta query always fails even if data is correct
- Problem with ‘save_post’ hook not running
- WordPress custom post type
- Custom Post Type with /%shop_name%/gallery/%gallery% permastruct?
- Would like to add a “leaderboard” (custom field) to a custom post type
- Edit post meta direct from post.php?
- Howto: use existing post_meta as options for a different metabox (checkboxes or list)
- predefined custom field on registration page
- Custom Post Type meta oembed html output resulting in WSoD
- Values inside a custom field to determine which category posts to display
- How to create content automatically when a post is published?
- Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
- Multisite – Echo admins profile meta
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- Rich Custom Field for Custom Post type not saving
- Add auto increment value to custom meta
- Custom post type submenu sorted by specific meta_key & meta_value
- Updating User Meta from Custom Post Field Upon Publish Not Working
- Display and Allow users to edit their own profiles
- Return only custom post types for the page, not all
- Change the contents of a dropdown through the admin panel?
- Advanced search form with filters for custom taxonomies and custom fields
- Retrieve post data via WPDB class
- Top 30 Songs using Custom Post Type
- Advice Needed for Post Meta Database Efficiency
- fetch meta fields inside a widget
- Querying meta values within an array
- Create action running on trashed_post hook to modify post_meta value
- Post AND page parameter for WP function
- Random meta field from specific custom post type
- Custom post type – update_meta not working
- Trying to display posts by authors in with specific user meta
- why get_post_meta is returning 0?
- Custom Post Type meta value is being saved in array, instead of just the string (as value)
- Save post_parent in a custom post type
- Custom Form Data save after Login User
- Use a Variable in update_post_meta as the $meta_key
- Save multiple checkboxes with Types
- 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?
- Update an existing post in a custom post type
- Check for custom field value in different post type than current one and do something
- Changing to different post type maintains the redirection?
- Post Meta for Custom Post Types
- How do I add the “orange counter” next to a Custom Post Type?
- getEntityRecords/useEntityRecords: How to use CPT metadata?
- I am having a problem with fetching product data in the Gutenberg block editor
- CPT meta values intermittently return empty
- Quering a post object based on another related post object
- rest_api_init is not getting invoked inside a Class
- Need some suggestions with Relationship fields and CPT/ACF
- Normal Posts and Custom Posts with Date Query
- Optimizing storage of Post Meta Entries
- Allowing a CPT post to be edited by a single user role