Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to grab xprofile data?

  • Avatar of sameast
    sameast
    Participant

    @sameast

    Hi

    I looking to change the structure off buddypress so the when you search for a member instead of just the member avatar and name and activity listed i would like to list some extra information from each members profiles.

    (this page) http://buddy.users32.interdns.co.uk/members/

    I have downloaded all the file and see that this section is in the members-loop.php. I can delete parts of this but as far as adding sections from the members profile im not sure how to do this as the profile fields are in the profile-loop.

    Any ideas on how to merge these together, bad in need off help in this.

    Thanks

Viewing 14 replies - 1 through 14 (of 14 total)
  • Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    If you want to get information out of the custom xprofile fields, you’ll need to use some of the functions in the profile-loop. I don’t think there are any core BP functions that allow you to pull a specific profile field by name or ID, so you’ll have to create a profile loop (<?php if ( bp_has_profile() ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>), then a profile field loop (<?php if( bp_profile_group_has_fields() : while ( bp_profile_fields() ) : bp_the_profile_field(); ?>) and then loop through the items, picking out the ones you want by field name. Use the code in profile-loop.php as a template for what you want to insert into members-loop.

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Boone is right; however there is a way to post specific xprofile fields!

    Check out a nifty function called bp_profile_field_data().

    Say I have an xprofile field called “Bio”.

    I’d use this code snippet:

    bp_profile_field_data('field=Bio');

    This will echo the “Bio” xprofile field of the displayed user.

    If you want to manipulate the data, use:

    bp_get_profile_field_data('field=Bio');

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Oho, I learn something new every day!

    So r-a-y – since it’s profile-field specific, you can probably skip while (bp_profile_fields() ) : bp_the_profile_field() right? #toolazytotrymyself

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Yes you can skip the while loop!

    Avatar of blgdra
    blgdra
    Participant

    @blogadera

    We’ve been working with this function before. What would be an example if hiding a field if the data is empty

    if bp_the_profile_field_edit_value() :

  • bp_profile_data(‘field=blip’)
  • else :

  • Nothing
  • endif;

    We have these custom fields appear on all member profiles sidebar and not all profile fields will have data. If the fields are empty they should hide.

    Any help…

Avatar of sameast
sameast
Participant

@sameast

Hi guys i couldn’t get it to show information about the profiles on the member-loop.php with

bp_profile_field_data(‘field=Bio’);

but i managed to get it to work with this one

bp_member_profile_data(‘field=Postcode’);

Hope this help someone thanks guys

Avatar of blgdra
blgdra
Participant

@blogadera

nm on our note. was completely the long and wrong way. can accomplish with css and using the function mentioned. it already hides if empty…der

Avatar of blgdra
blgdra
Participant

@blogadera

wonder if the same would work for a profile field group?

Avatar of gaysurfers
gaysurfers
Participant

@gaysurfers

Hi r-a-y

I have tried to post specific xprofile fields with no success.

It did work but since I installed the new version of buddypress (Version 1.2.2.1) it seems to have stopped working.

http://www.gaysurfers.net/members/

I have tried the following:

<div class=”item-meta”><?php bp_profile_field_data( ‘field=Country’ ) ?> – <?php bp_profile_field_data( ‘field=Surf Spot’ ) ?></div>

and also

<div class=”item-meta”><?php bp_member_profile_data( ‘field=Country’ ) ?> – <?php bp_member_profile_data( ‘field=Surf Spot’ ) ?></div>

I don’t know which one to use, but anyway none of them works. Is there some more code I need to add for it to work?

Thanks

Avatar of Andy Peatling
Andy Peatling
Keymaster

@apeatling

Try

<?php bp_profile_field_data( 'field=Country&user_id=' . bp_get_member_user_id() ) ?>

Avatar of gaysurfers
gaysurfers
Participant

@gaysurfers

YEAH!!! It’s working!!

Tx Andy!

Avatar of Matt Edminster
Matt Edminster
Participant

@chiinook

Hey Gents … picking up on the question posed by @blgdra here, is there a conditional statement I can use to show the field only when it is populated, or even only when populated with a given value?

I have
`Field Title: `
and would like to hide the Field title as well as the value when there is no value.

Avatar of Hugo
Hugo
Moderator

@hnla

Try:
`if (bp_get_profile_field_data(‘field=thefield’))
or
if (bp_get_profile_field_data(‘field=thefield’) == ‘string’)
`

Avatar of Damian
Damian
Participant

@timersys

Hi Guys im trying to do the same on a custom wordpress page but it seems that
if ( bp_has_profile() ) always returns false and i dont know why.
I even tried to put this on my custom page.

I need to load any file or globalize a variable?
I just need to make this work inside a custom page within wordpress.
Thanks for all the help

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

You must be logged in to reply to this topic.