Created
December 10, 2011 20:25
-
-
Save billerickson/1456229 to your computer and use it in GitHub Desktop.
Create a UNIX timestamp based on two meta fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 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 https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress | |
* | |
* @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 ) ) | |
return; | |
$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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment