Tagged: Age, bp-xprofile-custom-field-types, code, Xprofile Fields
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
CarstenHi 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- This reply was modified 6 years, 2 months ago by Brajesh Singh.
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
CarstenPlease 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?
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 quotesPlease 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
BrajeshHi 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.
You must be logged in to reply to this topic.