Skip to content

Instantly share code, notes, and snippets.

@ryelle
Created November 27, 2012 19:21
Show Gist options
  • Select an option

  • Save ryelle/4156393 to your computer and use it in GitHub Desktop.

Select an option

Save ryelle/4156393 to your computer and use it in GitHub Desktop.
Datepicker in Metabox
<?php
function display_meta_box( $post, $args ) {
// Get the date (if this is a post) we're editing
$archive_date = get_post_meta( $post->ID, '_guns-archive-date', true );
if ( ! $archive_date )
$archive_date = date( 'F d, Y' );
else
$archive_date = date( 'F d, Y', $archive_date );
// Enqueue Datepicker + jQuery UI CSS
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/smoothness/jquery-ui.css', true);
// Enqueue Custom styles
wp_enqueue_style( 'guns_2012-archive-meta-box', get_template_directory_uri() . '/css/admin.css' );
?>
<script>
jQuery( document ).ready( function( $ ) {
$("#archive-date").datepicker({
dateFormat: "MM dd, yy",
defaultDate: <?php echo $archive_date; ?>
});
} );
</script>
<table class="form-table">
<tr>
<th scope="row">
<label for="archive-date">Schedule post date:</label>
</th><td>
<div class="guns_2012-select-item-wrapper">
<input type="text" name="archive-date" id="archive-date" value="<?php echo $archive_date; ?>" />
</div>
</td>
</tr>
</table>
<?php
wp_nonce_field( 'save', 'guns_2012-select-item-meta-box' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment