BuddyDev

Search

[Resolved] Check if checkbox have data and print corresponding member name


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21550

    Actually code need to work outside of BuddyPress. On theme page.


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21563

    Hi Pause,
    Here is how you can loop on that array and print the values.

    
    foreach ( $user_ids as $user_id ) {
    	echo "For User:".bp_core_get_user_displayname( $user_id ). ' Data:' . xprofile_get_field_data("Field Name", $user_id );
    
    }
    

    I thought the question was related to how do you get the ids to loop around it. This is just an example. You will need to create your own displayable content loop.

    Also, the previous code can be used any place. It does not need to be used in any loop. Since we are using BP_User_Query, BuddyPress needs to be active on teh site.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21573

    Hi,

    we are getting pretty close now. Thanks a lot.

    I got now list of users printed but how can I print those users with link to their member page automatically.
    That loop now prints just user names.


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21574

    Hi,
    i got this working with links now. Thanks for your patience with this.

    So to sum up this the outcome is that i can now print all users who have checked option ‘tyres’ from checkbox and print their display name with link to their profile page.

    bp_core_get_userlink( $user_id );
    $url = bp_core_get_user_domain( $user_id );
    $username = bp_core_get_username( $user_id );

    $user_query = new BP_User_Query(
    array(
    ‘xprofile_query’ => array(
    array(
    ‘field’ => 10,
    ‘value’ => ‘tyres’,
    ‘compare’ => ‘LIKE’,
    ),
    ),
    ‘populate_extras’ => false,
    )
    );

    $user_ids = $user_query->user_ids;

    foreach ( $user_ids as $user_id ) { ?>
    “>
    <?php
    echo ” “.bp_core_get_user_displayname( $user_id ). ‘
    <br>’ . xprofile_get_field_data(“”, $user_id );

    }


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21575

    Hi,

    just to polish little more. What about printing user avatar image with link ?


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21583

    HI Pause,
    There are various functions available in BuddyPress for that. I will suggest taking a look at BP Template to get more info about them.

    Some of the useful functions you may use are:-

    
    bp_core_get_user_domain( $user_id ); // Url of the user profile.
    
    bp_core_get_userlink( $user_id ); // link to user profile.
    
    bp_core_fetch_avatar( array( 'item_id' => $user_id ) ); // get user avatar.
    
    

    and so on.

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 10
    Pause on #21596

    Thanks Brajesh! Case solved.


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21606

    Thank you.

The topic ‘ [Resolved] Check if checkbox have data and print corresponding member name’ is closed to new replies.

This topic is: resolved
Subscribe