Return to Snippet

Revision: 66311
at April 16, 2014 07:54 by fedek6


Initial Code
/**
 * Date field
 * 
 */

/**
 * Display the metabox
 */
function date_custom_metabox() {
	global $post;
	$year = get_post_meta( $post->ID, 'year', true );
?>
	<p><label for="startdate">Rok:</label><br />
		<input id="startdate" size="37" name="year" class="event-date" value="<?php if( $year) { echo $year; } ?>" /></label></p>
<?php
}

/**
 * Process the custom metabox fields
 */
function save_custom_date( $post_id ) {
	global $post;	
	
	if( $_POST ) {
		update_post_meta( $post->ID, 'year', $_POST['year'] );
	}
}

// Add action hooks. Without these we are lost
add_action( 'admin_init', 'add_custom_metabox' );
add_action( 'save_post', 'save_custom_date' );


/**
 * Add meta box
 */
function add_custom_metabox() {
	add_meta_box( 'custom-metabox', 'Year', 'date_custom_metabox', 'post', 'normal', 'high' );
}

Initial URL

                                

Initial Description
Additional option for Wordpress post (year in this case). You can get it's content in template file by:
`<?php>ID, 'year', true ); ?>`

Initial Title
Option [Year] for Wordpress post

Initial Tags
php, wordpress

Initial Language
PHP