It’s been about six months since my original Custom Metaboxes post announcing the release of this code library for easily creating metaboxes. If you haven’t had a look at it since then, I highly recommend you hop on Github and look at the latest version and the wiki.
Some of the features:
- The ability to create metaboxes with a simple array rather than a ton of code. Compare this tutorial (without our library) to these examples (with our library).
- Choose from 20 included field types, or add your own field types
- You can limit the metabox to specific post types, page template, page IDs, or create your own filter for where it should show up
- This can be used by both themes and plugins. And as long as you initialize it correctly (see bottom of example-functions.php), it can be used by a theme and as many plugins as you like at the same time.
My favorite field types:
- WYSIWYG. If you’re using WordPress 3.3, this will automatically use the new wp_editor which gives you a ton of flexibility.
- Taxonomy field types (select, radio, multicheck). If you’re dealing with a lot of taxonomies, the default metabox provided by WordPress takes up a lot of screen real estate. Include taxonomies in your custom metabox instead. Using select or radio is also a great way to force users to only select one taxonomy term.
- File upload. Use the built-in media uploader to allow the user to upload any file they want. You can also store the attachment ID in case you want to retrieve other image sizes.
- Title. If your metabox has a lot of fields in it, use the title field type to create subheadings and instructions.
- Text (standard, medium, and small). This is as simple as it comes, but also the one you’ll use most often.
- text_date_timestamp. This one uses a date picker to let the user select a date, and then saves it as a UNIX timestamp. This is great for event metaboxes because you can then query based on the date.
The contributors of this code library, in no particular order, include: Andrew Norcross, Jared Atchison, Travis Smith, Randy Hoyt, Jeremy Pry, Andrew Ryno, Patrick Forringer, Chris Olbekson, Stefan Crain …and me.
Please use this code, and consider contributing any improvements you make. If you create any field types or show_on filters, post them on the wiki. If you find any bugs, post them in issues (and even better, post the fix!).