1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// Add custom meta box for selecting last date of post function custom_last_date_meta_box() { add_meta_box( 'custom-last-date-meta-box', 'Last Date of Post', 'custom_last_date_meta_box_callback', 'post', 'side', 'default' ); } add_action('add_meta_boxes', 'custom_last_date_meta_box'); // Callback function to display the custom meta box function custom_last_date_meta_box_callback($post) { // Retrieve the current last date of the post, if available $last_date = get_post_meta($post->ID, 'custom_last_date', true); ?> <label for="custom_last_date">Select the last date of the post:</label> <input type="date" id="custom_last_date" name="custom_last_date" value="<?php echo esc_attr($last_date); ?>" /> <?php } // Save custom meta box data function save_custom_last_date_meta_box_data($post_id) { // Check if this is an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Check if nonce is set if (!isset($_POST['custom_last_date_meta_box_nonce'])) { return; } // Verify that the nonce is valid if (!wp_verify_nonce($_POST['custom_last_date_meta_box_nonce'], 'custom_last_date_meta_box')) { return; } // Check if user has permissions to save post data if (!current_user_can('edit_post', $post_id)) { return; } // Save the custom last date if (isset($_POST['custom_last_date'])) { update_post_meta($post_id, 'custom_last_date', sanitize_text_field($_POST['custom_last_date'])); } } add_action('save_post', 'save_custom_last_date_meta_box_data'); |
How to add extra date option with published and last modified date?
How to add extra date option with published and last modified date?
To do this, put this code in functions.php of your wordpress site.