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.
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');
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
Yes you can skip the while loop!
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
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
wonder if the same would work for a profile field group?
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
Try
<?php bp_profile_field_data( 'field=Country&user_id=' . bp_get_member_user_id() ) ?>
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.
Try:
if (bp_get_profile_field_data('field=thefield'))
or
if (bp_get_profile_field_data('field=thefield') == 'string')
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