BuddyDev

Search

Code Snippet 'Add Xprofile fields to the member code'

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

    Hi Brajesh, I found the members-loop under the template pack and copied it to my child theme. So far so good.
    I inserted the code here inside members loop copied the field ID 578 to the ‘Date Field Name’ as described (wp-admin/users.php?page=bp-profile-setup&mode=edit_field&group_id=1&field_id=578)

    But still no luck. Obviously this is not the right place to place the code?

    `/**
    * 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’ );
    */

    <?php echo xprofile_get_field_data( ‘578’, bp_get_member_user_id() );?>

    ?>
    </div>

    <div class=”action”>

    <?php`

    Regards
    Carsten

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

    Hi Carsten,
    When you visit members directory, do you see some php code? If you do, the file is correct.

    There is an issue with the above code though.

    You are not closing the php block correctly.

    The code should go after the

    
    ?>
    
    

    in your theme

    Instead of this

    
    
    <?php echo xprofile_get_field_data( 578, bp_get_member_user_id() );?>
    
    ?>
    
    

    It should be like

    
    
    ?>
    
    <?php echo xprofile_get_field_data( 578, bp_get_member_user_id() );?>
    
    

    We are putting our code after the closed php block. If it does not show you anything, I can post a snippet for bp-custom.php that will wok with all themes.

    Regards
    Brajesh

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

    Is this the right place to insert the snippet?
    Sorry it does not show anything in the fields, so a snippet for bp-custom.php would be much appreciated, thanks.

    <?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’ );
    */
    ?>
    <?php echo xprofile_get_field_data( ‘578’, bp_get_member_user_id() );?>
    </div>

    Regards
    Carsten

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

    Please put the following in your bp-custom.php

    
    
    /**
     * Show age field in members directory.
     */
    function buddydev_show_age_field_in_directory() {
    
    	$field_id_or_name = 578; // You can either use field name or ID.
    
    	echo xprofile_get_field_data( $field_id_or_name, bp_get_member_user_id() );
    }
    
    add_action( 'bp_directory_members_item', 'buddydev_show_age_field_in_directory' );
    
    

    Does this work for you?

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

    No, sorry, I put the code before the closing tag, but no values. I am not a Jedi master in PHP, so It could be my lack of skills…
    Are backtick’s around ID or name not necessary?

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

    Hi Carsten,
    Since we are using field ID here, the quotes are not needed.We don’t use backtick in php. It is single or double quotes

    Please verify the correctness of field id again and make sure that the user has data for Age field.

    Also, if feasible, Please share me your complete bp-custom.php on pastebin(and link here).

    I can look into it and find the problem.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #18193
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #18194

    Hi Carsten,
    Thank you.

    Everything is correct except the field id is set to 1 instead of 478 in the code. Please update and check that.

  • Participant
    Level: Yogi
    Posts: 1117
    calu on #18195
    This reply has been marked as private.
  • Participant
    Level: Yogi
    Posts: 1117
    calu on #18196
    This reply has been marked as private.

You must be logged in to reply to this topic.

This topic is: not resolved