Skip to:
Content
Pages
Categories
Search
Top
Bottom

How can I retrieve the current member id within members-loop.php

  • How can I retrieve the current member id when running through the members-loop.php?
    The following ways don’t work(I’ve already tried them.)
    `$bp->loggedin_user->id`—This just repeats because there is only one logged in user from his/her logged in perspective.
    `$bp->loggedin_user->id`—This just returns false for all members because this is from the main members loop not on any specific profile page.

    Ultimately I’m trying to perform a query in members-loop.php like the following.
    `if ( bp_has_members( ‘type=online&search_terms=’.$CURRENT_MEMBER_ID))`
    How can I pull the current member’s id???? Any help would be greatly appreciated.
    Thanks.
    -Alex

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    Generally it is not a good idea to use bp_has_members inside a bp_has_members loop.
    It probably won’t work, well maybe in BP 1.6.

    Anyhow, you could try:
    `
    $user_id=bp_get_member_user_id();
    if ( bp_has_members( ‘type=online&populate_extras=0&include=’.$user_id))
    `

    I basically use the approach below to check ‘online’ within members-loop:
    (why? don’t recall, but probably because the above approach didn’t work )

    `
    // put this at the top of members-loop

    $keep_checking_online = true;

    function check_user_online_str($get_active_str){
    $needles = array(‘hour’, ‘day’, ‘month’, ‘week’, ‘year’);
    foreach ($needles as $needle) {
    if (stripos($get_active_str, $needle)!==FALSE) return false;
    }
    return true;
    }

    //in the while loop, put this

    <?php
    $get_active_str = bp_get_member_last_active();
    if ($keep_checking_online) {
    $is_online = check_user_online_str($get_active_str);
    if ($is_online) echo “Online Now!”;
    else {
    echo $get_active_str;
    $keep_checking_online = false;
    }
    }
    else echo $get_active_str;
    ?>

    `

    The $keep_checking_online var is used so that the loop stops checking after it finds somebody not online now. This is possible because for bp_has_members( bp_ajax_querystring( ‘members’ ) ) returned members are ordered by last_active.

    But we use an online span of 59 minutes – while BP defaults to using 5 minutes.
    So you would need to adjust the function check_user_online_str().
    If it passes the $needles check, then parse the string to check for ‘minutes’ and ‘seconds’.
    If you find ‘minutes’, then get the number after ‘active’ and decide if you want to return true or false.

Viewing 1 replies (of 1 total)
  • The topic ‘How can I retrieve the current member id within members-loop.php’ is closed to new replies.
Skip to toolbar