0

How to get the user meta fields no registration hook in wordpress, for examples we are registering the user in wordpress rest api, after user registration from mobile need to add function that get the user along with meta field values to perform some function in wordpress side.

added the user registration action hook "user_register" that returns the newly register user email, username and id etc, but unable to get the meta field values

   add_action( 'user_register', 'custom_registration_action', 10, 1 );

function custom_registration_action( $user_id ) {
    $user = get_userdata( $user_id );
    $schedule_time =  get_user_meta( $user_id, 'schedule_time', true );

    error_log($schedule_time);

}
  • How are you inserting the meta values, and how are you attempting to retrieve them? Can you add your code for each to your question. – Jacob Peattie Apr 18 '18 at 12:09
  • @JacobPeattie i'm trying to get the meta values inserted through rest endpoint using get_user_meta() function – Mehar Apr 18 '18 at 12:15
  • Does this hook executed before the meta values inserted ? – Mehar Apr 18 '18 at 12:15
  • No, it's not. But if there's something wrong with the way you're setting the values to begin with, or a mistake in your actual code, then it might be possible to find those issues. Otherwise all anyone can say is that what you want to do is possible but you're making a mistake or there's a conflict somewhere. – Jacob Peattie Apr 18 '18 at 12:18
  • any wordpress function to return the complete user object including all the meta fields by user id ? – Mehar Apr 18 '18 at 12:19

Your Answer

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

Browse other questions tagged or ask your own question.