Created
July 27, 2015 18:32
-
-
Save taniarascia/b971e5c40823927444ed to your computer and use it in GitHub Desktop.
Add meta to regular page post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // register your custom meta box | |
| function my_slider_properties_meta_box() { | |
| add_meta_box('my_slider_properties', 'Link Format Title URL', 'my_slider_properties', 'page', 'side', 'default'); | |
| } | |
| add_action('add_meta_boxes', 'my_slider_properties_meta_box'); | |
| // echo your custom meta box | |
| function my_slider_properties() { | |
| global $post; | |
| $my_slider_id = get_post_meta($post->ID, '_my_slider_id', true); | |
| echo '<p>My slider id</p>'; | |
| echo '<input type="text" name="_my_slider_id" value="' . esc_attr($my_slider_id) . '" size="40" />'; | |
| } | |
| // process your custom meta box while saving | |
| function my_slider_properties_save_meta($post_id, $post) { | |
| if ( !current_user_can( 'edit_post', $post->ID )) | |
| return $post->ID; | |
| $metas['_my_slider_id'] = $_POST['_my_slider_id']; | |
| foreach ($metas as $key => $value) { | |
| update_post_meta($post->ID, $key, $value); | |
| } | |
| } | |
| add_action('save_post', 'my_slider_properties', 1, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment