Add Meta Box To Custom Post Types In WordPress

WordPress is best open source which can be use to make any type of site, WordPress having lots of features like custom menu, many plugins, Easy installation and upgrades,Spam protection, Full user registration,Multiple authors etc.. with these features wordpress have one more best feature  which make wordpress usable in all type of sites is Custom Post types.

WordPress can have different types of content which are save in same place same database table wp_posts, So here comes custom posts types, Custom post types used to differentiate all saved content in database table wp_posts. There is one column post_type in table which used to differentiate all saved content. Now if you want to read more about post types then you can read it here. Now in this article what I want to explain is how we can add meta box into custom post types.

Adding meta box to custom post type is not difficult it use same function which we use to add meta box to posts or page(Posts and pages also a custom posts types.) So for example if we have custom post types “project” and we want to add meta box in “project” custom post types So we just have to add below code in functions.php file of theme :

<?php add_meta_box("feat_slider", "Featured Content Slider Options", "c_slider_meta", "project", "normal", "high"); ?>

Now in above code you can see we called one function add_meta_box and then pass some arguments in it. First argument is ‘id’ attribute of the edit screen section. Second arugument is title of meta box. Third Argument is callback function which print out HTML of meta box.Fourth and important argument post type name which is ‘project’ in this case, Fifth argument part of the page where the edit screen section should be shown (‘normal’, ‘advanced’, or ‘side’). Sixth argument priority of box where it should show (‘high’, ‘core’, ‘default’ or ‘low’).

So this is the way you can add meta box to wordpress custom post types. If you need any help then let me know. I will try to solve your issue asap.

I am wordpress Developer, WordPress Developer India and WordPress Freelancer. If you have any projects related to wordpress or PHP you can contact me.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *