Latest Post

How to Add Meta Boxes for Custom post Type in WordPress

How to Add Meta Boxes for Custom post Type in WordPress


How to Add Meta Boxes for Custom post Type in WordPress


This code use for you can your add Meta Boses in Custom post Type

<?php

function add_service_meta_boxes() {
add_meta_box("service_contact_meta", "Contact Details", "add_contact_details_service_meta_box", "service", "normal", "low");
}

function add_contact_details_service_meta_box()
{
global $post;
$custom = get_post_custom( $post->ID );

?>
<style>.width99 {width:99%;}</style>
<p>
<label>Address:</label><br />
<textarea rows="5" name="address" class="width99"><?= @$custom["address"][0] ?></textarea>
</p>
<p>
<label>Website:</label><br />
<input type="text" name="website" value="<?= @$custom["website"][0] ?>" class="width99" />
</p>
<p>
<label>Phone:</label><br />
<input type="text" name="phone" value="<?= @$custom["phone"][0] ?>" class="width99" />
</p>
<?php
}


/**
 * Save custom field data when creating/updating posts
 */
function save_service_custom_fields(){
  global $post;

  if ( $post )
  {
    update_post_meta($post->ID, "address", @$_POST["address"]);
    update_post_meta($post->ID, "website", @$_POST["website"]);
    update_post_meta($post->ID, "phone", @$_POST["phone"]);
  }
}
add_action( 'admin_init', 'add_service_meta_boxes' );

add_action( 'save_post', 'save_service_custom_fields' );

?>

No comments