BuddyDev

Search

Code Snippet 'Add Xprofile fields to the member code'

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

    Hi there, I found the ‘Add Xprofile fields to the members directory’ in the Code Snippets directory, and it is working flawless. Except for for the Birthdate selector, which apparently is not recognized by the code.

    Is there a way I can make it work with the Birthdate selector?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18003

    Hi Carsten,
    Please share the code that you are using to show the xprofile field.

    Regards
    Brajesh

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

    Hi Brajesh, it is the code from BuddyDevs own Code Snippet directory by bphelp:

    Add Xprofile fields to the members directory
    PHP
    // Here is one way you could add xprofile fields name as well as the value to the members directory!
    // Just remember to replace “Field-Name” with the names of your fields in the 5 variables in my code.
    // Also remember the field name is case sensitive. If you notice the pattern of 5 in my code you can
    // easily see how to add more fields if you need them. You can also use the div class bph_xprofile_fields
    // to adjust the CSS in your stylesheet. Place this code in bp-custom.php:
    add_action(‘bp_directory_members_item’, ‘bphelp_dpioml’);
    function bphelp_dpioml(){
    $bphelp_my_profile_field_1=’Field-Name’;
    $bphelp_my_profile_field_2=’Field-Name’;
    $bphelp_my_profile_field_3=’Field-Name’;
    $bphelp_my_profile_field_4=’Field-Name’;
    $bphelp_my_profile_field_5=’Field-Name’;
    if( is_user_logged_in() && bp_is_members_component() ) { ?>
    <div class=”bph_xprofile_fields” style=” margin-left: 25%;”>
    <?php echo $bphelp_my_profile_field_1 ?>: <?php echo bp_member_profile_data( ‘field=’.$bphelp_my_profile_field_1 ); ?><br />
    <?php echo $bphelp_my_profile_field_2 ?>: <?php echo bp_member_profile_data( ‘field=’.$bphelp_my_profile_field_2 ); ?><br />
    <?php echo $bphelp_my_profile_field_3 ?>: <?php echo bp_member_profile_data( ‘field=’.$bphelp_my_profile_field_3 ); ?><br />
    <?php echo $bphelp_my_profile_field_4 ?>: <?php echo bp_member_profile_data( ‘field=’.$bphelp_my_profile_field_4 ); ?><br />
    <?php echo $bphelp_my_profile_field_5 ?>: <?php echo bp_member_profile_data( ‘field=’.$bphelp_my_profile_field_5 ); ?><br />
    </div><?php
    }
    }

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18006

    Thank you. I will check and post back in an hour.

    Regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18065

    Hi Carsten,
    I have looked into it. There is a bug in bp_member_profile_data and it does not passes the field id. Since the field id is not available, the custom fields plugin is unable to know whether age is required or date.

    There is a solution. Inside the members loop you can use

    
    <?php echo xprofile_get_field_data( 'Date Field Name', bp_get_member_user_id()  );?>
    
    

    That will give the correct data.
    For efficiency, you can replace the field name with id too.

    Regards
    Brajesh

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

    Hi Brajesh, thanks for the code. I always find it difficult to locate Members Loop in the directory, could you please guide me, to which folder it is in?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18115

    Hi Carsten,
    You are welcome.

    1. You can use the above code anywhere you were able to use the previous snippet.
    2. You an find the members loop in your-child-theme(or theme)/buddypress/members/members-loop.php if it is not there, you can copy it from wp-content/plugins/buddypress/bp-templates/(bp-legacy or bp-nouveau depending on the active template pack)/buddypress/members/ directory.

    If it is not in your theme and you plan to modify it, copy it to yourtheme/buddypress/members/members-loop.php

    Regards
    Brajesh

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

    Thanks again, Brajesh

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

    Hi again, I am sorry, but I can’t get it to work.

    I inserted the snippet in bp-custom.php, changed ‘Date Field Name’ with ‘age’ according to the profile field, but it does not show the value.

    ‘For efficiency, you can replace the field name with id too.’
    Please explain what you mean by this?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18165

    Hi Carsten,
    I am sorry but you can not use the snippet in bp-custom.php directly. Are you using it with some hook? If yes, Please post the complete snippet here (or on pastebin). To post snippet here, please use backtick(`) to enclose the code.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved