• Hi,

    In user profile page, except of showing the fields data, I want to get the name and mobile number of current user to do something else. I am using PHP snippets and I wrote the following code to get the user name.

    <?php
    $display_name = um_user(‘display_name’);
    echo $display_name; // prints the user’s display name
    ?>

    BUT I cannot get the mobile number (field meta key is mobile_number) by using the following:

    <?php
    $display_mobile = um_user(‘mobile_number’);
    echo $display_mobile;
    ?>

    What am I doing wrong? Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @avatarcy

    Whose user’s data are trying to retrieve? Is it the currently logged-in user or a specific user? If you need to retrieve the data of a specific user, you will need the function um_fetch_user.

    Here’s an example:

    
    $user_id = 123;
    um_fetch_user( $user_id ); // if this function is not added, it will retrieve the currently logged-in user's data.
    $display_mobile = um_user( "mobile_number" );
    

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @avatarcy

    …Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

    Thread Starter avatarcy

    (@avatarcy)

    It works if the user is locked in. What about when you are not logged in and you are just viewing the profile page of a user. I want in this situation to get the name and mobile number of this user. Can I do this or you have to login in to get them?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @avatarcy

    IF you are viewing a profile while currently logged-out, you can try this code snippet:

    
    $user_id = um_profile_id();
    um_fetch_user( $user_id ); // if this function is not added, it will retrieve the currently logged-in user's data.
    $display_mobile = um_user( "mobile_number" );

    Regards,

    Thread Starter avatarcy

    (@avatarcy)

    Great, working just fine. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get field value’ is closed to new replies.