Created
July 30, 2014 12:45
-
-
Save yojance/cec1418a2ed50c641adc to your computer and use it in GitHub Desktop.
OptionTree Date 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
array( | |
'id' => 'spyr_demo_date_picker', | |
'label' => __( 'Date Picker', 'text-domain' ), | |
'desc' => __( 'Your description', 'text-domain' ), | |
'type' => 'date-picker', | |
'section' => 'your_section', | |
) | |
// Get the value saved on Theme Options Page | |
$spyr_demo_date_picker = ot_get_option( 'spyr_demo_date_picker' ); | |
// Get the value saved for a Page, Post or CPT ( Within the loop ) | |
$spyr_demo_date_picker = get_post_meta( $post->ID, 'spyr_demo_date_picker', true ); | |
// Checking if the date has passed | |
$date = new DateTime( ot_get_option( 'spyr_demo_date_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_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_picker_date_format', 'spyr_modify_date_picker_date_format', 10, 2 ); | |
function spyr_modify_date_picker_date_format( $format, $field_id ) { | |
if( 'spyr_demo_date_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