I’m having the same problem!
I have just one field I want to show in the Members Directory (members-loop.php), Current Location, and I’ve tried a few different code variations I found here in the forums with no luck.
I thought this one would do the trick, but no dice. With this code, if a member hasn’t filled out the Current Location field, it still shows the value of the last person in the list who did have it filled in.
<?php if ( $data = bp_member_profile_data( 'field=Current Location' ) ) : ?>
<?php echo $data ?>
<?php endif ?>
Anyone have any suggestions for me and @ariane1001?
Try:
$data = bp_member_profile_data( 'field=Current Location' );
if( $data != false )
echo $data;
Thanks for your response, @shanebp.
That code still has the fields repeating, but perhaps I entered it wrong? Since you didn’t include the php tags I’m not sure where they go; I did it this way:
<?php $data = bp_member_profile_data( 'field=Current Location' ); ?>
<?php if( $data != false ) ?>
<?php echo $data; ?>
Are you putting this code in the members-loop.php template?
Are you putting it in the designated area?
Look for this text: ‘If you want to show specific profile fields here you can,…’
Ah, actually in my most recent attempts I had started putting it right after that as a separate <?php section… But I just tried moving it within the code that actually has that comment (and removed the <?php stuff I added above), and it still doesn’t work.
Just to be sure we’re on the same page, I want it to show nothing if that profile field is blank, and otherwise show what’s been provided in that profile field… And right now, it’s showing, for example, “Los Angeles, CA” for the person who entered that location as well as the people after her in the list who didn’t enter a location.
I tested the code snippet in that template using the WP 2013 theme.
And it works as expected.
So something else is going on.
You might try using pastebin to share all the code on that page, then share the link here.
Hmm, okay.
First time using pastebin, but I think I did it right!
http://pastebin.com/ZbnYpWXm
Oh, I just realized that I shared the code in the members-loop.php file, but perhaps you meant the whole /members page? How would I go about sharing that?
And, FYI, this is a copy of the members-loop.php that I moved to my child theme. My theme is Klein from ThemeForest.
Try this:
<?php
/***
* If you want to show specific profile fields here you can,
* but it'll add an extra query for each member in the loop
* (only one regardless of the number of fields you show):
* bp_member_profile_data( 'field=the field name' );
*/
$data = bp_get_member_profile_data( 'field=Current Location' );
if( $data != false )
echo $data;
?>
Just checked the pastebin. If you use it as is, i understand why it is not working.
Why do you use a count in the members loop ? This is automated by BP for that loop.
And shane’s code is commented. Should be uncommented to work. (remove the stars)
Thanks for your feedback, @danbp.
When I copied everything into pastebin yesterday, I had the code commented out because it wasn’t working and I didn’t want it showing incorrectly on the page.
Later, I deleted that whole commented code section and replaced it with the last code @shanebp shared.
Here’s a new pastebin of the current code: http://pastebin.com/bynhRb2g
And here’s a screenshot of what that’s creating on my page right now: http://screencast.com/t/AcTotzQ2
I haven’t done anything else in this file, so the count code came from the theme developer, I guess. (Maybe you can tell from the screenshot what he was trying to accomplish with that code?)
Ok the count seems to be only a cosmetic change for the member directory.
See an original picture of this here.
A bit strange to use this trick as it exist and can be alered with css, but authors are sometimes strange….
What is the theme you use ? Maybe it contains some other “strange” things ? 😉
I’m using Klein, which I bought on ThemeForest: http://themeforest.net/item/klein-a-nittygritty-community-theme/5418518
Certainly possible that there’s some other strange stuff in there! I’ve spent a lot of time undoing some of the weird stuff I’ve come across.
Huh ? 😀
Klein a nitty gritty community theme. sic theme’s homepage pitch !
The heart of the matter; the basic essentials; the harsh realities.
Have you asked on the theme support ?
Well I thought it was a BuddyPress issue, which is why I came here. But if you’re all saying that the code I have should be working, then I will definitely contact theme support next.
Hi,
I have had the same problem and now, I have found a solution which works with my theme: just declare the variable $data (or whatever name you give it) as static before calling bp_get_member_profile_data or bp_member_profile_data like this:
<?php static $data = 'bla'; ?>
<?php do_action( 'bp_directory_members_item' ); ?>
<?php
/***
* If you want to show specific profile fields here you can,
* but it'll add an extra query for each member in the loop
* (only one regardless of the number of fields you show):
*
* bp_member_profile_data( 'field=the field name' );
*/
$data = bp_get_member_profile_data( 'field=Taetigkeit' );
if( $data != '' )
echo $data;
?>