Warning: DateTime::setTimestamp() expects parameter 1 to be long

I am new here, so sorry if I am posing this question incorrectly… but I am getting this error:

Warning: DateTime::setTimestamp() expects parameter 1 to be long

Read More

For this code:

if(!function_exists('sort_posts_by_time')) {
function sort_posts_by_time($a, $b) {

    // set the times from the meta values
    $time_a = new DateTime();
    $time_a->setTimestamp(get_post_meta($a->ID, '_jfc_start_date', true));
    if($start_time_a = get_post_meta($a->ID, '_jfc_start_time', true)) {
        $time_a->modify($start_time_a);
    }

    $time_b = new DateTime();
    $time_b->setTimestamp(get_post_meta($b->ID, '_jfc_start_date', true));
    if($start_time_b = get_post_meta($b->ID, '_jfc_start_time', true)) {
        $time_b->modify($start_time_b);
    }

    if($time_a == $time_b) {

        $time_a->setTimestamp(get_post_meta($a->ID, '_jfc_end_time', true));

        $time_b->setTimestamp(get_post_meta($b->ID, '_jfc_end_time', true));

    }

    return ($time_a->getTimestamp() > $time_b->getTimestamp()) ? 1 : -1;
}

}

The error specifically occurs within the code, above, here:

$time_a->setTimestamp(get_post_meta($a->ID, '_jfc_end_time', true));

$time_b->setTimestamp(get_post_meta($b->ID, '_jfc_end_time', true));

I am hoping someone can help me out, I have looked all over google search and haven’t found anything helpful, thank you!

Related posts