How to Create Custom WP Metabox

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.

(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


[insert-code id=3]


Leave a Reply