Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display single xprofile fields


  • hugodouchet
    Participant

    @hugodouchet

    Hi all,

    First of all, thx team for your great job! Buddypress is really good!

    So, I would like to display a field from xprofile fields.

    Ex. : I have a field named “country” and I want to display the value of this field on the profile page (or another).

    I search on the site but I dont find answers…

    Thx ;)

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

  • peterverkooijen
    Participant

    @peterverkooijen

    I got this solution here earlier. This in functions.php or bp_custom.php:

    function bp_custom_member_list_xprofile_data( $field ) {
    echo bp_custom_get_member_list_xprofile_data( $field );
    }
    function bp_custom_get_member_list_xprofile_data( $field ) {
    global $site_members_template;
    return xprofile_get_field_data( $field, $site_members_template->member->id );
    }

    And then this in the template:

    <?php if ( $company = bp_custom_get_member_list_xprofile_data('Company') ) : ?>
    <p><?php echo $company ?></p>
    <?php endif; ?>

    I didn’t come up with this myself. Forgot who deserves the credit…

    EDIT:

    BTW, this seems to work as well:

    <p><?php echo bp_custom_get_member_list_xprofile_data('Company') ?></p>

    Or am I missing something?

    EDIT2:

    Or further cleaned up:

    function custom_xprofile( $field ) {
    echo bp_custom_get_member_list_xprofile_data( $field );
    }
    function bp_custom_get_member_list_xprofile_data( $field ) {
    global $site_members_template;
    return xprofile_get_field_data( $field, $site_members_template->member->id );
    }

    In the template:

    <p><?php custom_xprofile('Company') ?></p>


    hugodouchet
    Participant

    @hugodouchet

    Hi Peterverkooijen,

    Thanks for your help! This function works great!!

    But I have another problem now! :) In the list member, if I want to show the “company” field near the name (in the loop), what is the function to call to have the member id?

    Big thanks!


    peterverkooijen
    Participant

    @peterverkooijen

    I’d like to know as well. I’m not a php programmer. I’d noticed this function is specific for the members template, index I guess.

    global $site_members_template;

    I guess we need to add a global there. Or replace it in a separate function. I’ll try some things as soon as I have time.

    Ideally I’d like to have a function that works anywhere in the theme…


    hugodouchet
    Participant

    @hugodouchet

    Ok, thank you man,

    Your previously answer was very usefull! I’ll try some things too and post a message if i find solution ;)

    See ya


    hugodouchet
    Participant

    @hugodouchet

    Up! Anyone to help me? Thx ;)


    Tom
    Participant

    @jeffreeeeey

    Threads been quite helpful for me so far..

    I’m using Jet random members widget on the ‘members’ page and I’ve managed to get one of my profile fields to display there now, rather than a random field.

    Here’s what I done…

    In /directories/members/index.php find-

    <?php bp_the_site_member_random_profile_data() ?>

    and replace with-

    <?php echo bp_custom_get_member_list_xprofile_data('Gender') ?>

    where “Gender” is the name of the field you wish to display.

    Then in bp-custom.php (in your plugins folder), add this:

    //To add custom profile fiels to random members widget //
    function custom_xprofile( $field ) {
    echo bp_custom_get_member_list_xprofile_data( $field );
    }
    function bp_custom_get_member_list_xprofile_data( $field ) {
    global $site_members_template;
    return xprofile_get_field_data( $field, $site_members_template->member->id );
    }

    I’m working on a few other tweaks now to try adding this custom field to the actual member listing part of the page now and I imagine it will work in the same sort of way. I’ll keep you posted.


    Tom
    Participant

    @jeffreeeeey

    Yup- just as I thought.. in members-loop.php find-

    <?php bp_the_site_member_last_active() ?>

    and change to-

    <?php echo bp_custom_get_member_list_xprofile_data('Gender') ?>

    Where “Gender” is the name of the profile field you wish to display.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display single xprofile fields’ is closed to new replies.
Skip to toolbar