How to Add Meta Boxes for Custom Post Type in WordPress
This code use for you can add Meta Boses in Custom post Type and this code add your function.php
file WordPress.
Custom meta boxes are Mostly used to provide a better user interface for adding custom fields (metadata) into your content.
<?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' ); ?>
Author: Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.
Trending Posts
Tags
ACF
Ading custom columns
admin
Bootstrap
Cart Price
categories
Change Price
class
Code
comments
Create
Creating custom post Type
CSS
current
custom
Customizing
Custom Post
Custom Post Type
Custom Taxonomy
database
Date
Fatch
form
function
HTML
Image
Install
javascript
jQuery
Menu
PHP
Post
Post Type
Price
product
responsive
Resular price
Single product
Table
taxonomy
Theme
Title
woocommerce
Wordpress
Wordpress Code