0

I am trying to add a function in the init hook that will call another hook like this :

add_action( 'init', 'loadAfterUserRegistrationHook' );
    function loadAfterUserRegistrationHook(){
    add_action( 'user_meta_after_user_register', 'createNewPost' );  
}    

function createNewPost( $response ){
global $userMeta;

$userID = $response->ID;
$user = new WP_User( $userID );

$role = $userMeta->getUserRole();

if( $role = 'artiste' ){ 

    $newPost = array(
      'post_title'    => $user->nickname, 
      'post_content'  => $user->description,
      'post_status'   => 'pending',
      'post_author'   => $userID,
      'post_type'     => 'cpt_artists'
    );

    $post_id = wp_insert_post( $newPost );
    error_log('Post ID : '.$post_id);

    wp_set_object_terms( $post_id, array('dj'), 'artist-category');

   }
 }

Why is the function createNewPost is not being executed?

1

perhaps running it on the user_register hook?

add_action( 'user_register', 'loadAfterUserRegistrationHook' );
    function loadAfterUserRegistrationHook(){
    add_action( 'user_meta_after_user_register', 'createNewPost' );  
}

See: http://codex.wordpress.org/Plugin_API/Action_Reference/register_form

  • No because i need to set custom taxonomy and they are not loaded if i don't run it on the init hook. – devwin Jan 24 '14 at 15:54
  • I believe your custom taxonomy is available at this point. Have you tried running it yet? – Godwinh Jan 24 '14 at 16:01
  • Yes i have tried, createNewPost function is lauched but my term is not set :(. – devwin Jan 24 '14 at 16:06
  • Godwinh please be my savior lol – devwin Jan 24 '14 at 16:55
  • The one way i find to set terms is add_action( 'init', 'testFunction' ); function testFunction(){ wp_set_object_terms( 120, array('dj'), 'artist-category'); } But i can't have the id of the post – devwin Jan 24 '14 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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