Skip to content

Instantly share code, notes, and snippets.

@leanneromak
Last active August 29, 2015 14:26
Show Gist options
  • Save leanneromak/4fb525efa89b5dcc40d8 to your computer and use it in GitHub Desktop.
Save leanneromak/4fb525efa89b5dcc40d8 to your computer and use it in GitHub Desktop.
<?php
/*
* Displaying single value
*/
?>
<p>Posted on: <?php the_field('date_picker'); ?></p>
<?php
/*
* Create PHP DateTime object from Date Piker Value
* this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
*/
$date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
echo $date->format('d-m-Y');
/*
* Order Posts based on Date Picker value
* this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
*/
$posts = get_posts(array(
'meta_key' => 'custom_order', // name of custom field
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
if( $posts )
{
foreach( $posts as $post )
{
setup_postdata( $post );
// ...
}
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
}
/*
* Format examples
*/
$js = "yymmdd"
$php = "Ymd"
$js = "dd/mm/yy"
$php = "d/m/Y"
$js = "yy_mm_dd"
$php = "Y_m_d"
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment