Default and custom types already have default fields that we can fill in, but what it we need custom data for these post types? In this kind of need, we can opt to create custom metaboxes which will contain custom fields for the desired post types.
To make the implementation of a custom metabox easier, I created an abtract class that you can find here.
So, to create a custom metabox, simply follow the steps below:
Step 1: Copy theĀ Metabox Class from WDT-Framework
Step 2: Extend the class and defined the needed functons:
- _showForm() – this is where you should define the content of your metabox (normally a set of custom fields)
[insert-code id=1]
- _saveMetadata() – this is where you should define how the fields are saved.
[insert-code id=2]
Step 3: Instantiate your class.
Parameters:
$metabox_id
(string) the id of your metabox; must be unique
$metabox_title
(string) the title if your metabox
$screens
(array) what screens should the metabox appear; normally an array of post types
$context
(string) options: normal, side, advanced
$priotity
(string) options: high, low, default
Examples:
[insert-code id=3]