Custom Metaboxes and Fields levels up to v2.0

While preparing for my WordCamp Tampa talk the other day, I was referencing the excellent Custom Metaboxes and Fields for WordPress plugin by WebDevStudios when I realised that they had quietly released v2.0.

For those unaware, Custom Metaboxes and Fields allows you to add custom boxes to your post editor (for posts, pages, or any other post type) to collect extra data that aren’t supported by the traditional WordPress editor fields. Think of things like adding fields for the author, ISBN and cost of a book when writing a book review, or creating your own support system by creating fields for user, issue, status and responses.

CMB2 as it is now known is a complete rewrite of the codebase. It generally works the same as version 1.x, but you will need to tweak a few things. Once you upload the new files to your theme/plugin, you’ll need to update your hooks and filters. Where the original filter for adding new metaboxes was cmb_meta_boxes, you now need to use cmb2_meta_boxes. This (changing cmb_ to cmb2_) applies to all hooks and filters.

You’ll also need to change how you include the core files. You used to have to check for a class and then require a file, on init. All that’s required of you now is include/require the main init.php file. There’s more details on the specifics of how to do this in the GitHub repository.

Another change is that you need to modify the ‘pages’ parameter to ‘object_types’, which is a much better descriptor of what the parameter actually does (this is where you define what post types the metaboxes should apply to – pages implies some sort of tie to the page post type).

The last main change is that WebDevStudios have now released this as a plugin on, for those who are a little intimidated by the installation process from GitHub. With the .org plugin, you can now use the plugin installer, and simply edit example-functions.php to add the metaboxes that you need.

This is a really nice milestone in the development of my favourite tool for adding custom metaboxes and I’m happy to see its continued development.

To learn how to implement Custom Metaboxes and Fields, you can read the tutorial I wrote a while ago, or look at example-functions.php in CMB2.

Download CMB2Get the .org plugin

Leave a Reply