-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost-meta.php
70 lines (54 loc) · 2.35 KB
/
post-meta.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* Add custom metabox to the new/edit page
*/
function sp2016_add_metaboxes(){
add_meta_box("sp2016_social_status", "Social Post Type", "sp2016_social_status", "sp-social", "normal", "low");
}
add_action('add_meta_boxes', 'sp2016_add_metaboxes');
// Build media meta box
function sp2016_social_status() {
global $post;
?>
<div class="custom-meta social-status">
<label for="social-status">Select post type:</label>
<select id="social-status" name="_custom_social_status" id="">
<option <?php selected('0', $post->_custom_social_status); ?> default value="0">none</option>
<option <?php selected('twitter', $post->_custom_social_status); ?> value="twitter">twitter</option>
<option <?php selected('facebook', $post->_custom_social_status); ?> value="facebook">facebook</option>
<option <?php selected('instagram', $post->_custom_social_status); ?> value="instagram">instagram</option>
</select>
<br/>
</div>
<div class="custom-meta">
<label for="image-url">Image URL for this post:</label>
<input id="image-url" class="short" title="" name="_custom_image_url" type="text" value="<?php echo $post->_custom_image_url; ?>">
<br/>
</div>
<div class="custom-meta">
<label for="external-url">External URL for this post:</label>
<input id="external-url" class="short" title="" name="_custom_external_url" type="text" value="<?php echo $post->_custom_external_url; ?>">
<br/>
</div>
<?php
}
/*
* Save the metabox vaule
*/
function sp2016_save_metabox($post_id){
// check autosave
if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
if( ! empty($_POST["_custom_social_status"]) ) {
update_post_meta($post_id, "_custom_social_status", $_POST["_custom_social_status"]);
}
if( ! empty($_POST["_custom_image_url"]) ) {
update_post_meta($post_id, "_custom_image_url", $_POST["_custom_image_url"]);
}
if( ! empty($_POST["_custom_external_url"]) ) {
update_post_meta($post_id, "_custom_external_url", $_POST["_custom_external_url"]);
}
}
add_action('save_post', 'sp2016_save_metabox');
?>