BuddyDev

Search

Clarifying question about adding Xprofile fields to the members directory

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #47259

    Hi there, I’m using this code snippet to add Xprofile fields to the members directory

    https://buddydev.com/snippets/614-614/

    And this to Show Buddypress Xprofile Field Data After The username in The Members Directory.

    https://gist.github.com/KaineLabs/f431ef4177757e61f9a638607c9879e0

    My clarifying question is, why two different methods are used for basically the same purpose, that is adding xprofile fields to profiles in the members directory?

    Regards
    Carsten

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #47260

    Is it possible combining these two sets of codes into one, so you have only one set of xprofile fields under the profiles in the members directory?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #47271

    Hi Carsten,
    I will definitely support using xprofile_field_get_data today.

    We have a tutorial about it from long long ago
    https://buddydev.com/fetching-and-showing-only-specific-fields-from-buddypress-xprofile-data/

    I am not sure what you want to combine from those 2 and they are doing the same thing but the post by ‘bphelp’ is a bit dated and I will avoid it today.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #47274

    Hi Brajesh, thanks for the clarification, that is very useful.

    You could say that the advantage of bphelp is that it shows field name as well as data, that’s what I ment of combining, since the field name is nice to have with some xprofile fields to make sense.

    But I will go with xprofile_field_get_data as you recommended.

    I have managed to add age profile field to the xprofile_field_get_data code, some time ago (below), but I’m not able to reconstruct what I did then with other profile fields, so I hop the tutorial clarifies 😉

    function yzc_add_xprofile_field_data_after_username( $name ) {
    	if ( bp_is_members_directory() ) {
    
    		$field_data      = xprofile_get_field_data( 'Age:', bp_get_member_user_id() );
    		$field_data_gender = xprofile_get_field_data( 'Gender:', bp_get_member_user_id() );
    
    		return $name . " <span class='bp-user-age'> <br/>" . $field_data_gender . ", " . $field_data . "</span>";
    
    	}
    
    	return $name;
    }
    
    add_filter( 'bp_member_name', 'yzc_add_xprofile_field_data_after_username', 10 ); 
    
    add_filter( 'bp_rest_members_get_items_query_args', 'buddydev_exclude_logged_and_admin_users' );
    
  • Participant
    Level: Yogi
    Posts: 1117
    calu on #47279

    Hi Brajesh, I have been looking at the tutorial about Fetching and Showing only Specific fields from BuddyPress XProfile data, and I can see that this is another approach, adding code into the members-loop.php, instead of bp-custom.php like KaineLabs?

    I have inserted
    $Fra= xprofile_get_field_data( 'Fra:' , bp_get_member_user_id() );//fetch the text for location

    between bp_nouveau_before_loop(); ?> and <?php bp_nouveau_after_loop(); ?>

    but the field is not displayed. Is it because the location is not defined?

    Could you give me an example of the complete function?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #47327

    Hi Carsten,
    Thank you.

    Please allow me to put a better sample for you today.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #47328

    Hi Brajesh, thank you, looking forward to that.

    Regards
    Carsten

You must be logged in to reply to this topic.

This topic is: not resolved