• while creating users wordpress uses user_register hook. I need to have post created with new user creation and have the post meta data with corresponding the user meta data upon creation. The user will have extra fields like address, country,etc. So I need those extra fields to be saved in the postmeta data of the post created.

Viewing 1 replies (of 1 total)
  • anjanap-

    It’s very simple job.

    After successful creation of user you can apply below code.

    // Create post object
    $my_post = array(
      'post_title'    => 'Your Post title',
      'post_content'  => 'Your Post Content.',
      'post_status'   => 'publish',
      'post_author'   => 1, /* You may setup your created user id if he has
                               capabilities of doing so. */
      'post_category' => array(1) /* As per requirement */
    );
    
    $post_id = wp_insert_post( $my_post );

    By executing wp_insert_post,your post will be created.

    Now you have only one thing remaining – User’s Metadata.

    Here you may use add_post_meta or update_post_meta.

    add_post_meta($post_id, 'address', 'Ghatlodiya,Patidar Road, Ahmedabad');
    add_post_meta($post_id, 'country', 'INDIA');
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post creation with user creation’ is closed to new replies.