Skip to:

Age for Each User instead of Age for Logged in User

  • 1a-spielwiese



    What have I to write there:

    <?php echo bpdev_get_age_from_dob(tag,bp_loggedin_user_id()); ?>

    – instead of bp_loggedin_user_id() – for getting displayed the information at issue not for the logged-in user, rather for each member (who is mentioned on the member-page)?



    1. I have a profile field ‘Tag’ (= day) (description: ‘der Geburt oder Teamgründung’ = ‘of birth or team fundation’).

    2. I inserted that code into my reddle-child/functions.php:

    * Get Age from BuddyPress date of Birth
    * <a href='' rel='nofollow'>@param</a> string $dob_field_name :name of the DOB field in xprofile, like Dob or Date of Birth
    * <a href='' rel='nofollow'>@param</a> int $user_id : the user for which you want to retrieve the age
    * <a href='' rel='nofollow'>@param</a> string $format: the way you want to print the difference, look t  for the acceptable agrs
    * @return string :the formatted age in year/month
    function bpdev_get_age_from_dob($tag,$user_id=false,$format="%y"){
    $user_id=bp_displayed_user_id ();
    $dob_time=xprofile_get_field_data($tag, $user_id);//get the datetime as myswl datetime
    $dob=new DateTime($dob_time);//create a DateTime Object from that
    $current_date_time=new DateTime();//current date time object
    //calculate difference
    $diff= $current_date_time->diff($dob);//returns DateInterval object
    //format and return
    return $diff->format($format);

    3. With inserting

    <?php echo bpdev_get_age_from_dob(tag,bp_loggedin_user_id()); ?>

    into my reddle-child/buddypress/members/members-loop-.php I get displayed for all members the age of the logged-in user (what is of course stupid).

    So, what have I to change for getting displayed the indiviual age of each member?

    Cfr. as well:


  • The topic ‘Age for Each User instead of Age for Logged in User’ is closed to new replies.
Skip to toolbar