Buddypress Age

These two functions work together to calculate a buddypress users age. Keep in mind that you need to have a 'birthday' profile field for this to work.

You can call either function by passing the user Id, so omega_get_age(22); to get the age of user ID22 or omega_get_birthday(22); to get their birthday, don't forget to echo them out. You can also replace the id number with: bp_loggedin_user_id() to get the current users info.

I used the omega_ prefix for the functions, this is actually a theme name of mine that uses the above snippet. Using a unique prefix for a function lowers the risk of that function existing and then getting the 'unable to redeclare error'.

If you are still getting that error that means that you pasted the omega_get_birthday() function twice in your code. I do not believe buddypress has a function by that name. But a last ditch effort is to just change the omega_ to something else everywhere in the snippet.

Thanks for your very very useful code!
I am having a problem implementing the code in the members-loop.php file. I would like to have the age displayed next to all members, but using bp_loggedin_user_id() gives every user the same age (the age of the person logged in...).
I was able to properly use echo omega_get_age(bp_displayed_user_id()); in the member-header file to display the age on the user's profile page, but am stuck regarding the member-loop. Hopefully you have some idea?
Lastly, all ages are displaying one year younger, and I'm not sure why. For example, someone born in May 1986 is shown as 23 years old...

Hey, feel free to store your code here on the site, It is backed up often and you can sort through all your code based on your author name for future use. In my daily dev job I can't function without this site.

First off you need to have the birthday field in the buddypress profile, you can add that from the buddypress admin pages.

Next place these two functions in your child theme functions.php file, if you are not doing a child theme then they go in the buddypress functions.php - child themes rule so check out how to use them on buddypress.org

Then just call the omega_get_age($member_id) function from a template file and that's it. You will need to pass the $member_id either as a number to test it out or get that programatically using a buddypress function that gets the user's id.

First of all thank you very much for your codes !! I' ve already used 3 of them , unfortunately I am a noob yet . so some things I don't get like I should . I have the same problem like question nr.5 here , with the difference that he understood your answer nr.6:
"Try accessing the member id from within the members loop using: $member_id = bp_get_member_user_id(); " ,
Is this the only code I gotta put there or I miss something ? It calls only member ID . Can you pls. write here exact code I should put in member-loop.php to get the result right behind the name of every member ? Thanks your code above I already have it perfectly running in the single page, but not in members directory , I run latest buddypress 1.2.8 default theme and the latest wordpress 3.1 , Thank you Daniel .

I am at a loss, you may need to look for another snippet. All of the code on this site is experimental and I do my best to help out the coders but sometimes debugging this stuff requires first hand access to the files and hours and hours of tinkering. I just dont have any spare time at the moment.

Was wondering is it possible to use this snippet and have the age show up in one section of the profile but in the users profile that has all the fields from the registration shown have the birth date?

Calling the function omega_get_age() between the parenthesis should do it. This is ancient code. I would actually be surprised if this is still working with the latest BP. I wrote this when it was at ver 1.0. - Good luck

Hi Adam
firstly thanx for your help out to WP sufferers. There re not many helpful guys like you around.
My question is this:
I have the latest Wp and BuddyPress, On the registration form I only want 1 form element appears (regarding to age) and that is AGE select box. (no day, month or year, just age). So users can only enter their age. And other users can only search age. So registration form and search form should have only age box. How can I do that? What files to change and how could you please explain and help me out on that please.
Thanx.