Skip to:
Content
Pages
Categories
Search
Top
Bottom

xprofile fields displaying data from another user


  • carrieoke13
    Participant

    @carrieoke13

    Hi,

    I’ve added an extended profile using xprofile fields, and I’m displaying some of the fields on the members list page. But, if someone has left a field blank, their profile is displaying the data for the last member who did complete that field. (So, if I didn’t put my city but the person displayed before me did, that person’s city is showing in my profile.) You can see what I mean here: http://yarngroup.wpengine.com/members/

    I copied members-loop.php to a buddypress folder in my main theme folder, and here’s the code I added to display the name, city and state:

    <?php
    
    				/**
    				 * Fires inside the display of a directory member item.
    				 *
    				 * @since 1.1.0
    				 */
    				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' );
    				  */
    				  
    				  
    				  bp_member_profile_data( 'field=Your Name' );
    			
    				  echo '<br />';
    				 bp_member_profile_data( 'field=City' ); echo ', '; bp_member_profile_data( 'field=State' ); 
    				  echo '<br />';
    				
    					  
    				?>
     
     <a href="<?php bp_member_permalink(); ?>">View Member Profile</a>
    			<div class="action">
    
    				<?php
    
    				/**
    				 * Fires inside the members action HTML markup to display actions.
    				 *
    				 * @since 1.1.0
    				 */
    				do_action( 'bp_directory_members_actions' ); ?>
    
    			</div>
    
    		</li>
    
    			
    	<?php endwhile; ?>
    
    	</ul>
    <div class="clear"></div>

    Am I missing some code? Thanks!

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

  • shanebp
    Moderator

    @shanebp

    To determine if the issue is in your theme, try switching momentarily to a WP theme like 2013.
    You’ll need to copy members-loop.php to a buddypress folder in that theme.

    You can only echo the data if it exists.
    Try:

    $your_name = bp_get_member_profile_data( 'field=Your Name' );
    if ( $your_name != false ) 
       echo $your_name;

    carrieoke13
    Participant

    @carrieoke13

    Thanks, Shane. It’s still happening even if I switch themes. I tried this code and it is still showing the wrong name in the last member listed.


    shanebp
    Moderator

    @shanebp

    Then there is some other issue specific to your install.
    I believe wpengine has aggressive caching turned on by default.

    Try:

    $your_name = false;
    $your_name = bp_get_member_profile_data( 'field=Your Name' );
    if ( $your_name != false && $your_name != NULL ) 
       echo $your_name;

    carrieoke13
    Participant

    @carrieoke13

    Thanks, Shane.

    So I have it working now using:

    
    $your_city= xprofile_get_field_data( 'City' ,bp_get_member_user_id());
    				
    if ( $your_city != false ) 
       echo $your_city; 

    I am super new to BuddyPress – is there a reason not to do it that way? I really appreciate your help.


    shanebp
    Moderator

    @shanebp

    Interesting… so the value is being cached somewhere… an object?

    As you may have noted, bp_get_member_profile_data does not require passing in the member ID – IF you are in a members loop. You can pass in the ID as an array argument.

    But xprofile_get_field_data can be used anywhere and always requires passing the ID.

    is there a reason not to do it that way?

    bp_get_member_profile_data will try to get the data from the global before resorting to a database call.
    xprofile_get_field_data will always make a database call – for each piece of data.
    So there would be some performance hit.


    carrieoke13
    Participant

    @carrieoke13

    Ah, that totally makes sense.

    I just used the default members-loop.php – is there something I should look for in the code that could be causing the odd behavior?

    Thanks!
    Carrie


    shanebp
    Moderator

    @shanebp

    Unless you are explicitly using the bp-default theme, not recommended, you should always use these templates: buddypress\bp-templates\bp-legacy\

    iow. this members-loop:
    buddypress\bp-templates\bp-legacy\buddypress\members\members-loop.php

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar