WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got my user registration to automatically create a post with the user_register hook however the title shows up as (no title) can someone help me with what I'm doing wrong here?


$userinfo = get_userdata($user_id);
$disname = $userinfo->display_name;

function create_new_user_post($user_id){
        if (!$user_id>0)return;

        // Create post object
        $my_bio_post = array(
           // 'post_type' => 'ggs_user_post_type',
             'post_title' => $disname,
             'post_content' => 'Put cool content here!',
             'post_status' => 'publish',
             'post_author' => $user_id

        // Insert the post into the database
        $bio = wp_insert_post( $my_bio_post );

        //and if you want to store the post ids in 
        //the user meta then simply use update_user_meta
share|improve this question
up vote 1 down vote accepted

Your function create_new_user_post() can't see:

$userinfo = get_userdata($user_id);
$disname = $userinfo->display_name;

Place those within the function so that the function has access to those variables.

share|improve this answer
Oh wow, I'm an idiot. Thanks josh and s_ha_dum – BenRacicot Mar 6 '13 at 15:47

$disname is not set. You define it outside the function's scope. The same is true with $userinfo. And you don't have $user_id set either. It is passed into the function by the add_action mechanism. You need to pull both of those into the callback function as Josh said (and pick his answer. He got here first, and the answer is correct, just not very detailed. Consider this "supplemental".)

function create_new_user_post($user_id){
    if (!$user_id>0) return;

    $userinfo = get_userdata($user_id);
    $disname = $userinfo->display_name;
    // and the rest
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.