Auto-Generate Post on User Registration
-
Basically I’d like a post created automatically when a new user registers. The new user should be tied to the post as its author. I have a form builder plug installed that allows me to collect additional info, one field being “Restaurant Name.” I’ve looked at my DB in phpMyAdmin and confirmed restaurant_admin living in user_meta.
I’m still a coding baby, but I feel like I’m on the right track here. I tosesd the following (plus the applicable php open/close tags) into a file and installed and activated it like a plugin, but it’s not creating the post. Can anyone tell me the glaring mistakes I’m sure I’m making here?
add_action( 'user_register', 'restaurant_profile_create', 10, 1 ); function restaurant_profile_create( $user_id ) { // Get user info $user_meta = get_userdata( $user_id ); // Create a new post $user_post = array( 'post_title' => $user_meta->restaurant_name, 'post_type' => 'post', ); // Insert the post into the database $post_id = wp_insert_post( $user_post ); }
- The topic ‘Auto-Generate Post on User Registration’ is closed to new replies.