Saturday 4 March 2017

Adding Meta Boxes to Post Types in WordPress


If you’ve ever used WordPress to build a website for yourself or a client, or you work for a company whose website is powered by WordPress, you would have seen and used meta boxes. In the past, we’ve covered adding custom meta boxes to WordPress. In this article, we’ll go two steps further explaining their relationship and integration with post types, including how to use the data saved in a meta box in the WordPress front-end.
Win 1 of 5 Netlify PRO annual accounts – worth $490 each!
Win A Netlify PRO Account!
Adding Meta Boxes to Post Types Screen
Most (if not all) of the PHP functions, their parameters and Action hooks that are handy in creating meta boxes have been covered by Narayan Prusty.
To add a meta box to the any post type editing screen, the add_meta_box() is used and subsequently hooked to the add_meta_boxes action.
The code below adds a metabox to the post edit screen. Take note of global_notice_meta_box_callback, the function that is called to display the form field(s) in the meta box. We’ll come to that later.
function global_notice_meta_box() {

add_meta_box(
‘global-notice’,
__( ‘Global Notice’, ‘sitepoint’ ),
‘global_notice_meta_box_callback’,
Source: https://managewp.org/articles/14506/adding-meta-boxes-to-post-types-in-wordpress




source https://williechiu40.wordpress.com/2017/03/04/adding-meta-boxes-to-post-types-in-wordpress/

No comments:

Post a Comment