Thread Starter
Pete
(@perthmetro)
Hmm not as friendly as i’d like 😉
I have no idea how to insert the custom field in all of that
Thread Starter
Pete
(@perthmetro)
I’ve reviewed everything I can that doesn’t make my brain explode all over the house… i’m sorry i’m one of these leechers who wishes they knew php but really knows my tiny brain will never get there… ooo look a shiny ball!
Assuming the custom field is called dyear
, something like:
function age_in_years() {
global $post;
$year_of_birth = get_post_meta( get_the_ID( $post->ID ), 'dyear', true );
$date1 = strval( $year_of_birth );
$date2 = strval( date( 'Y') );
$age = $date2 = $date1;
return $age;
}
should work if used in the Loop as <?php echo age_in_years();?>
Thread Starter
Pete
(@perthmetro)
It only spits out the year? my custom field is cf_year
Thread Starter
Pete
(@perthmetro)
ahhh changed the = to a –
Thread Starter
Pete
(@perthmetro)
function age_in_years() {
global $post;
$year_of_birth = get_post_meta( get_the_ID( $post->ID ), ‘dyear’, true );
$date1 = strval( $year_of_birth );
$date2 = strval( date( ‘Y’) );
$age = $date2 – $date1;
return $age;
}