Created
March 4, 2012 06:40
-
-
Save BronsonQuick/1971054 to your computer and use it in GitHub Desktop.
Add meta boxes to the Testimonials WordPress CPT
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
<?php /** | |
* Adds a custom meta box to the Testimonials editor page for collecting | |
* Testimonial meta. | |
* Refer to: https://gist.github.com/1971046 for the Custom Post Type Setup | |
* | |
* @since 1.0 | |
*/ | |
function sennza_add_meta_boxes() { | |
add_meta_box( 'sennza_testimonials_meta_box', __( 'Testimonial Details' ), 'sennza_testimonials_meta_box', 'testimonial', 'side', 'core' ); | |
} | |
add_action( 'add_meta_boxes', 'sennza_add_meta_boxes' ); | |
/** | |
* The contents of our custom meta box. | |
* | |
* @since 1.0 | |
*/ | |
function sennza_testimonials_meta_box() { | |
global $post_ID; | |
echo '<div id="testimonial_meta">'; | |
wp_nonce_field( plugin_basename( __FILE__ ), 'sennza_testimonial_nonce' ); | |
$parent_type = get_post_meta( $post_ID, 'parent_type', true ); | |
$parent_name = get_post_meta( $post_ID, 'parent_name', true ); | |
$child_name = get_post_meta( $post_ID, 'child_name', true ); | |
$parent_location = get_post_meta( $post_ID, 'parent_location', true ); | |
// Mum or Dad ?> | |
<p> | |
<label for="parent_type" style="width:30px; display:inline-block;"><?php _e( 'Mum:' ); ?></label> | |
<input type="radio" id="parent_type" name="parent_type" value="mum" style="width:20px; display:inline-block;" <?php checked( 'mum', $parent_type ); ?>/> | |
<label for="parent_type" style="width:30px; display:inline-block;"><?php _e( 'Dad:' ); ?></label> | |
<input type="radio" id="parent_type" name="parent_type" value="dad" style="width:20px; display:inline-block;" <?php checked( 'dad', $parent_type ); ?>/> | |
</p> | |
<?php | |
// Parent's Name ?> | |
<p> | |
<label for="parent_name" style="width:80px; display:inline-block;"><?php _e( "Parent's Name:" ); ?></label> | |
<input type="text" id="parent_name" name="parent_name" value="<?php echo $parent_name; ?>" size="25" /> | |
<?php | |
// Childen's Names ?> | |
<p> | |
<label for="child_name" style="width:80px; display:inline-block;"><?php _e( "Child's Name:" ); ?></label> | |
<input type="text" id="child_name" name="child_name" value="<?php echo $child_name; ?>" size="25" /> | |
<?php | |
// Location ?> | |
<p> | |
<label for="parent_location" style="width:80px; display:inline-block;"><?php _e( "Location:" ); ?></label> | |
<input type="text" id="parent_location" name="parent_location" value="<?php echo $parent_location; ?>" size="25" /> | |
</div> | |
<?php | |
} | |
/** | |
* Save the meta associated with a testimonial | |
* | |
* @since 1.0 | |
*/ | |
function sennza_save_testimonial_meta() { | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return; | |
if ( empty( $_POST[ 'sennza_testimonial_nonce' ] ) || ! wp_verify_nonce( $_POST['sennza_testimonial_nonce'], plugin_basename( __FILE__ ) ) ) | |
return; | |
update_post_meta( $_POST[ 'ID' ], 'parent_type', $_POST[ 'parent_type' ] ); | |
update_post_meta( $_POST[ 'ID' ], 'parent_name', $_POST[ 'parent_name' ] ); | |
update_post_meta( $_POST[ 'ID' ], 'child_name', $_POST[ 'child_name' ] ); | |
update_post_meta( $_POST[ 'ID' ], 'parent_location', $_POST[ 'parent_location' ] ); | |
} | |
add_action( 'save_post', 'sennza_save_testimonial_meta' ); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment