Hello Friends,
If you would like to add some more attribute on your post page. We can use post meta for this. For example you want to add a new post for event creation. You want Event Title, Event Description and Event Start Date. Please review the code below for this specific job and you can make your changes according to your requirement. Open function.php under your theme and add the below code with your changes.
<?php
/*
* Custom Event Caption Box
*/
add_action( 'admin_init', 'caption_metabox' );
function caption_metabox()
{
add_meta_box( 'Event', //Event is your post type
'Event Start Date',
'caption_review_meta_box',
'Event', 'normal', 'high'
);
}
/* Define the HTML FOR EVENT START DATE */
/* Add custom post meta boxes */
function caption_review_meta_box($post) {
$event_start_date = esc_html( get_post_meta( $post->ID, 'event_start_date', true));
?>
<table style="width:100%;">
<tr>
<td style="width: 20%">Event Start Date</td>
<td style="width: 40%">
<input type="text" name="event_start_date" value="<?php echo $event_start_date; ?>" />
</td>
</tr>
</table>
<?php
}
// Save custom post meta values
add_action( 'save_post', 'caption_metabox_fields', 10, 2 );
function caption_metabox_fields( $caption_metabox_id )
{
if (isset($_POST['event_start_date'])){
update_post_meta( $caption_metabox_id, 'event_start_date', $_POST['event_start_date'] );
}
}
?>
0 Comment(s)