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:

    public function _showForm($post) {
    	$value = get_post_meta($post->ID, 'reference', true);
        	<input type="text" name="reference" value="<?php echo $value ?>" />
    protected function _saveMetadata($post_id, $user_inputs) {
        //OK, it's safe for us to save the data now.
        update_post_meta($post_id, 'reference', $user_inputs['reference']);

Step 3: Instantiate your class.

(string) the id of your metabox; must be unique

(string) the title if your metabox

(array) what screens should the metabox appear; normally an array of post types

(string) options: normal, side, advanced

(string) options: high, low, default


new PostExtraOptions('opt1', 'mymetabox', array('post', 'page'), 'side', 'default');
new PostExtraOptions('opt2', 'mymetabox', array(page'), 'normal', 'high');


Leave a Reply