Skip to:
Content
Pages
Categories
Search
Top
Bottom

Age for Each User instead of Age for Logged in User


  • 1a-spielwiese
    Participant

    @1a-spielwiese

    Question:

    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)?

    —–

    Background:

    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='https://buddypress.org/community/members/param/' rel='nofollow'>@param</a> string $dob_field_name :name of the DOB field in xprofile, like Dob or Date of Birth
    * <a href='https://buddypress.org/community/members/param/' rel='nofollow'>@param</a> int $user_id : the user for which you want to retrieve the age
    * <a href='https://buddypress.org/community/members/param/' 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"){
    if(!$user_id)
    $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:

    https://buddypress.org/support/topic/modifying-the-member-list/#post-203566

    and

    https://buddypress.org/support/topic/display-age-on-profile-page/#post-121850

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