Skip to:
Content
Pages
Categories
Search
Top
Bottom

specific profile fields in the loop, if empty show content previous member


  • ariane1001
    Participant

    @ariane1001

    Hi,
    I am trying to extend the loop with some extra profile fields using this code:

    <?php bp_member_profile_data('field=Present position'); ?><br/>
    <?php bp_member_profile_data('field=Phone number'); ?><br/>
    <?php bp_member_profile_data('field=Email address'); ?> <br/>

    It works but members with empty profile fields get the data from the Previous member.
    Website is behind a login but it looks like this:

    Ariane Gordijn
    06 123 456 78
    ariane@ca-editors.com

    Len ‘t Hoen
    06 123 456 78
    ariane@ca-editors.com

    Tanja Baars
    Marketing & communication employee
    427
    t.baars@airborne.nl

    How can I change the code so the empty fields stay empty?

    Thanks in advance,
    Ariane

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

  • alscott99
    Participant

    @alscott99

    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?


    shanebp
    Moderator

    @shanebp

    Try:

    $data = bp_member_profile_data( 'field=Current Location' );
    if( $data != false ) 
       echo $data; 

    alscott99
    Participant

    @alscott99

    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; ?>

    shanebp
    Moderator

    @shanebp

    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,…’


    alscott99
    Participant

    @alscott99

    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.


    shanebp
    Moderator

    @shanebp

    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.


    alscott99
    Participant

    @alscott99

    Hmm, okay.

    First time using pastebin, but I think I did it right!

    http://pastebin.com/ZbnYpWXm


    alscott99
    Participant

    @alscott99

    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.


    shanebp
    Moderator

    @shanebp

    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;
    
    ?>

    alscott99
    Participant

    @alscott99

    Still no go. 🙁


    danbp
    Participant

    @danbp

    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)


    alscott99
    Participant

    @alscott99

    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?)


    danbp
    Participant

    @danbp

    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 ? 😉


    alscott99
    Participant

    @alscott99

    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.


    danbp
    Participant

    @danbp

    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 ?


    alscott99
    Participant

    @alscott99

    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.


    schorsch2
    Participant

    @schorsch2

    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;  
    	?>
Viewing 17 replies - 1 through 17 (of 17 total)
  • The topic ‘specific profile fields in the loop, if empty show content previous member’ is closed to new replies.
Skip to toolbar