Create a UNIX timestamp based on two meta fields

* Create a UNIX timestamp based on two meta fields
* @author Bill Erickson
* @uses text_date_timestamp (for date, UNIX)
* @uses text_time (for time, XX:XX AM/PM)
* @link
* @param int $post_id
function be_timestamp_meta( $post_id ) {
// Limit to 'event' post type. You can put whatever limit you want here
if( 'event' !== get_post_type( $post_id ) )
$date = get_post_meta( $post_id, 'be_event_date', true );
$time = get_post_meta( $post_id, 'be_event_time', true );
if( !empty( $date ) && !empty( $time ) ) {
$date = date( 'm/d/Y', $date );
$timestamp = strtotime( $date . ' ' . $time );
update_post_meta( $post_id, 'be_event_timestamp', $timestamp );
add_action( 'save_post', 'be_timestamp_meta', 99 );
view raw hosted with ❤ by GitHub

Useful for sorting events by date AND time (ex: 8am event before 9am event)

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk