Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active January 4, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/561029638d83b7f7b98c79418ba644a6 to your computer and use it in GitHub Desktop.
Save tripflex/561029638d83b7f7b98c79418ba644a6 to your computer and use it in GitHub Desktop.
Output Age from custom date value in WP Job Manager Field Editor (requires PHP 5.3+)
<?php
// ^ the <?php above should only be in your functions.php file ONCE, at the top
// The filter is field_editor_output_as_value_METAKEY
// where you need to replace METAKEY with the actual meta key you want to filter the output for
//
// Below the example meta key used is "candidate_dob"
add_filter( 'field_editor_output_as_value_candidate_dob', 'smyles_output_age_from_dob' );
function smyles_output_age_from_dob( $value ){
// No need to process if empty value (0, false, null, etc)
if( empty( $value ) ) {
return $value;
}
// REQUIRES PHP 5.3+ (you should already be using this, if not, you have bigger problems to deal with)
// @see http://stackoverflow.com/questions/3776682/php-calculate-age
$age = date_diff( date_create( $value ), date_create('now') )->y;
return $age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment