Create Meta box and display on single.php


/***** Adding custom metabox on post type  *****/

add_action("add_meta_boxes", "listing_meta_box");
function listing_meta_box(){
add_meta_box('contact_info',__( 'Practice Information', 'realestate' ), 'contact_info', 'practice-areas', 'normal', 'low');

function contact_info() {
global $post;
$detail1 = get_post_meta($post->ID,'detail1',true)?get_post_meta($post->ID,'detail1',true):'';
$detail2 = get_post_meta($post->ID,'detail2',true)?get_post_meta($post->ID,'detail2',true):'';
$detail3 = get_post_meta($post->ID,'detail3',true)?get_post_meta($post->ID,'detail3',true):'';
$detail4= get_post_meta($post->ID,'detail4',true)?get_post_meta($post->ID,'detail4',true):'';
$detail5= get_post_meta($post->ID,'detail5',true)?get_post_meta($post->ID,'detail5',true):'';

<table class="form-table">
<th><label for="name">
<?php _e('Detail 1','realestate'); ?>
<td><input type="text" name="detail1" value="<?php echo $detail1; ?>" class="listing_input" /></td>

<th><label for="email">
<?php _e('Detail 2','realestate'); ?>
<td><input type="text" name="detail2" value="<?php echo $detail2; ?>" class="listing_input" /></td>
<th><label for="phone">
<?php _e('Detail 3','realestate'); ?>
<td><input type="text" name="detail3" value="<?php echo $detail3; ?>" class="listing_input" /></td>
<th><label for="mobile">
<?php _e('Detail 4','realestate'); ?>
<td><input type="text" name="detail4" value="<?php echo $detail4; ?>" class="listing_input" /></td>
<th><label for="fax">
<?php _e('Detail 5','realestate'); ?>
<td><input type="text" name="detail5" value="<?php echo $detail5; ?>" class="listing_input" /></td>

add_action('save_post', 'realestate_property_save_details');
function realestate_property_save_details(){
global $post;
//contact info
update_post_meta($post->ID, "detail1", $_POST["detail1"]);
update_post_meta($post->ID, "detail2", $_POST['detail2']);
update_post_meta($post->ID, "detail3", $_POST["detail3"]);
update_post_meta($post->ID, "detail4", $_POST["detail4"]);
update_post_meta($post->ID, "detail5", $_POST["detail5"]);

Display single.php

if ( is_singular('practice-areas') ) {
$key_1_value = get_post_meta( get_the_ID(), 'detail1', true );
$key_2_value = get_post_meta( get_the_ID(), 'detail2', true );
$key_3_value = get_post_meta( get_the_ID(), 'detail3', true );
$key_4_value = get_post_meta( get_the_ID(), 'detail4', true );
$key_5_value = get_post_meta( get_the_ID(), 'detail5', true );


Tagged: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: