Last active
August 29, 2015 14:02
-
-
Save ethanpil/19f24021165b2b429e28 to your computer and use it in GitHub Desktop.
Wordpress Add Custom Meta Box to Page
This file contains 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
//Code for template file: | |
global $post; | |
if ( get_post_meta($post->ID, 'active_page_showzipform', true ) ) : | |
//Checkbox is checked... do somehting | |
endif; | |
//Code for functions.php --- Begin Custom Code for Page Metabox | |
function active_add_meta_box() { | |
add_meta_box( | |
'active_metabox_pagesettings', // id | |
'Page Options', // title | |
'active_page_settings', // callback function | |
'page', // type of write screen | |
'side', // context | |
'low' // priority | |
); | |
} | |
add_action( 'add_meta_boxes', 'active_add_meta_box' ); | |
function active_page_settings(){ | |
global $post; | |
$custom = get_post_custom($post->ID); | |
$active_page_showzipform = $custom["active_page_showzipform"][0]; | |
?> | |
<input type="checkbox" name="active_page_showzipform" <?php if( $active_page_showzipform == true ) { ?>checked="checked"<?php } ?> /> Hide Zipcode Form | |
<?php | |
} | |
add_action('save_post', 'save_active_page_settings'); | |
function save_active_page_settings($post_ID = 0) { | |
$post_ID = (int) $post_ID; | |
$post_type = get_post_type( $post_ID ); | |
$post_status = get_post_status( $post_ID ); | |
if ($post_type) { | |
update_post_meta($post_ID, "active_page_showzipform", $_POST["active_page_showzipform"]); | |
} | |
return $post_ID; | |
} | |
//End Custom Code for Page Metabox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment