‘Date of birth’ field not being returned because private. Workaround?
-
This is happening in functions.php to fire up in members_loop:
Even though the Date of Birth is a private field I still need to pull it so I can calculate and display the user’s age. The below code works fine when I’m logged in as Admin but returns 0 when I’m logged in as a regular user which made me realize it’s probably because it’s set to private.
$dod = bp_get_member_profile_data( 'field=Date of birth' )
How do I get the field value straight from wp_bp_xprofile_fields?
The below isn’t working. I’m assuming it’s terribly wrong. I think I need to include in the db query the userID because it only pulls one value no matter who the user is but how do I get the displayed user’s ID (if that’s the case to begin with)? I managed to get this to work when viewing one’s profile page but I can’t seem to do it in members_loop.//Add fields in the member directory results function add_info_to_members_loop() { //$dateOfBirth = bp_get_member_profile_data( 'field=Date of birth' );//This isn't working global $wpdb; $dateOfBirth = array(); $dateOfBirth = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2"); $dob = $dateOfBirth[0]; /*This will work when I finally get the date of birth $today = date("Y-m-d"); $diff = date_diff(date_create($dob), date_create($today)); $state = bp_get_member_profile_data( 'field=State' ); echo 'Age '.$diff->format('%y') . ' - In ' . $state; */ } add_action( 'bp_directory_members_item', 'add_info_to_members_loop' );
Thank in advance.
- You must be logged in to reply to this topic.