How can I create let say 3 posts after the user finish the registration ?
The ideal outcome would be to create 3 posts using the user as the author of the posts and with some pre-defined values. (post title and slug)
The post title and slug would be created from info that the user will provide on the registration form.
An example:
User registers and provide Name, Surname, Email (all fields are mandatory)
Three posts are created and the user will be the author of each post.
Each post will have in the title and slug info from the registration form
- 1- Jon Doe Bio | jon-doe-bio
- 2- Jon Doe Portfolio | Jon-doe-portfolio
- 3- Jon Doe Contact | jon-doe-contact
*In the example above it seems unnecessary to have the ability to edit the slug but there will be posts with words like: in, is, at, and, that will be removed otherwise. Also note that the “pre-defined values would be: Bio, Portfolio and Contact.
It would be close to the “welcome” posts created by wordpress after install.
Any idea of how to ?
I know I need to use wp_insert_post( $my_post );
and probably add_action('user_register', 'some_function');
but I don’t know how to create 3 posts in one shot using wp_insert_post( $my_post );
and how to trigger that after the user finish the registration process.
Any idea how to accomplish this ?
Thanks in advance.
You kind of answered the question yourself already,
Create a function that will create the 3 posts ex:
and you hook that function using
user_register
hookUpdate
When you hook a function to
user_register
the function receives the user id so you can use that to get whatever information you want about that user ex:and now $user is a USER object so you can change the post title to user the user info ex: