I have a custom field, attached to a custom post The custom post is a profile (user) the Custom field a date, stored as a unix timestamp.
I evaluate like this:
function born_today_func( $atts ) {
extract(shortcode_atts(array(
'birthday' => get_post_meta(get_the_ID(), 'wpcf-your_cf_slug', true),
), $atts)
);
if((date('d', strtotime($birthday)) == date('d')) && (date('m', strtotime($birthday)) == date('m'))){
return 1;
}else{
return 0;
}
}
add_shortcode( 'born-today', 'born_today_func' );
It does not matter if I use this as a short code, as a function or whatever, the line:
if((date('d', strtotime($birthday)) == date('d')) && (date('m', strtotime($birthday)) == date('m')))
Does not correctly evaluate the date of custom field with the current date.
I have following results for TODAY:
Profile 1
12/05/08
person 2
11/05/08
Person 3
01/05/15
But obviously only 12/05 (Profile 1 ) should be echoed.
It is worth to mention that this are NOT my only profiles, but all other dates are NOT returned
(as example 13/05/08
is NOT returned)
What am I doing wrong?
How do I correctly check a UNIZ TIMESTAMP for dd/mm and output ONLY if dd/mm is corresponding with TODAY?
I am not interested in including the 29th February, thats a entire other matter.
My code is correct, it evaluates SOMETHING, but not the EXACT what it should.
I hope somebody can help.
FYI: This returns the EXACT SAME results as my above code:
$birthDate = get_post_meta(get_the_ID(), 'wpcf-birthday', true);
$time = strtotime($birthDate);
if(date('m-d') == date('m-d',$time)) {
return 1;
}else{
return 0;
}
Additional info suggested by Luke:
var_dump returns:
$birthDate:
string(10) "1210550400" string(10) "1421020800" string(10) "1210464000" string(10) "1430438400"
$time:
int(-49532903345) bool(false) int(64072123846) int(202922721043)
not sure what I can do with that now?
Regardless all (surely) helpful comments and answers here, the solution is much simpler. just do not convert.
this code will do his job as expected:
function born_today_func( $atts ) {
extract(shortcode_atts(array(
'birthday' => get_post_meta(get_the_ID(), 'wpcf-birthday', true),
), $atts)
);
if(((date('d', $birthday)) == date('d')) && (date('m', $birthday)) == date('m')){
return 1;
}else{
return 0;
}
}
add_shortcode( 'born-today', 'born_today_func' );