Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_get_member_user_id() returns false


  • yousan
    Participant

    @hogetan

    Hello.
    I am trying to get a certain user’s xprofile field data.
    I found a topic.
    https://buddypress.org/support/topic/display-a-value-of-a-particular-custom-profile-field/

    So I tried

    global $current_user;
    $user_id = bp_get_member_user_id();
    var_dump($user_id); // <--- false!
    $class = xprofile_get_field_data('weight', $user_id );

    bp_get_member_user_id() returns false.

    At bp-members-template.php Line 708,

    	function bp_get_member_user_id() {
    		global $members_template;
    		$member_id = isset( $members_template->member->id ) ? (int) $members_template->member->id : false;

    it uses $members_template global variable.
    I dumped it, but it was NULL.

    Should I initialize or call any function before calling bp_get_member_user_id() ?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

  • Henry Wright
    Moderator

    @henrywright

    The likely reason why bp_get_member_user_id() is returning NULL is you are using it outside the members loop. See the Playing with the user’s ID in different contexts article for info on how to get the member’s ID in the various contexts that exist within BP.


    yousan
    Participant

    @hogetan

    Thanks Henry.

    I can get the loggedin user_id with bp_loggedin_user_id() function by the article you shown.

    I had to use bp_get_member_user_id() at the member loop.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘bp_get_member_user_id() returns false’ is closed to new replies.
Skip to toolbar