WordPress create custom meta boxes

3

This post is explaining creating wordpress custom meta boxes/meta data in easy,secure & proper way.A post meta box is a draggable box shown on the post adding/editing page. Its purpose is to allow the user to enter information in addition to the main post content.

There are two types of meta boxes.

1-Meta data

Check this attachment to get an idea about the meta box.
Wordpress custom meta box

Post metadata is data that’s saved in the wp_postmeta table in the database.
Following functions are using working with post meta data.
add_post_meta() – Add post metadata.
update_post_meta() – Update post metadata.
delete_post_meta() Delete post metadata.
get_post_meta()Retrieve post metadata.

2-Taxonomy terms

Check this attachment to get an idea about the Taxonomy in wordpress.
Wordpress custom post types

I’ll explain about creating a custom post types in next post.

Creating a custom post meta box

ok.Now I’m going to show you how to create custom meta box in wordpress.
Look at this diagram and you can understand what I’m going to do now.
Wordpress custom meta box

1-Add meta boxes on the ‘add_meta_boxes’ hook.

Open your theme’s folder functions.php file and add the following codes at the end of that file.
wp-content/themes/yourthemefolder/functions.php

 

2-Display the meta value

 

3-Save post meta on the ‘save_post’ hook

 

That’s only you have to do. Now clear the browser cache and check the post edit/create page and you can see the custom meta data value there.

I’ll show how to create custom post type of wordpress in next post.

Share.

About Author

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.