Created
July 30, 2014 12:46
-
-
Save yojance/dc86eeacf1064fe3f8ea to your computer and use it in GitHub Desktop.
OptionTree Date Time Picker Option Type
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
// OptionTree Date Time Picker Option Type | |
// Example code when being used as a Metabox or | |
// Exported OptionTree file to be used in Theme Mode | |
array( | |
'id' => 'spyr_demo_date_time_picker', | |
'label' => __( 'Date Time Picker', 'text-domain' ), | |
'desc' => __( 'Your description', 'text-domain' ), | |
'std' => '', | |
'type' => 'date-time-picker', | |
'section' => 'your_section', | |
) | |
// Get the value saved on Theme Options Page | |
$spyr_demo_date_time_picker = ot_get_option( 'spyr_demo_date_time_picker' ); | |
// Get the value saved for a Page, Post or CPT ( Within the loop ) | |
$spyr_demo_date_time_picker = get_post_meta( $post->ID, 'spyr_demo_date_time_picker', true ); | |
// Checking if the date has passed | |
$date = new DateTime( ot_get_option( 'spyr_demo_date_time_picker' ) ); | |
$now = new DateTime( "now" ); | |
// Compare the 2 dates | |
// Not that this example assumes you have not changed the date format | |
// through the ot_type_date_time_picker_date_format filter like shown below | |
if( $now > $date ) { | |
echo 'Date is in the past'; | |
} else { | |
echo 'Date has not passed yet'; | |
} | |
// Change displayed format and returnd value | |
// Defaults to yy-mm-dd | |
// Not recommended but it's possible | |
add_filter( 'ot_type_date_time_picker_date_format', 'spyr_modify_date_time_picker_date_format', 10, 2 ); | |
function spyr_modify_date_time_picker_date_format( $format, $field_id ) { | |
if( 'spyr_demo_date_time_picker' == $field_id ) { | |
return 'mm-dd-yy'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment