Getting Started

Creating a simple meta box

After installing and activating the Meta Box plugin, open your theme’s functions.php file (or a PHP file of your plugin) and insert the following code:

add_filter( 'rwmb_meta_boxes', 'your_prefix_meta_boxes' );
function your_prefix_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array(
        'title'      => __( 'Test Meta Box', 'textdomain' ),
        'post_types' => 'post',
        'fields'     => array(
            array(
                'id'   => 'name',
                'name' => __( 'Name', 'textdomain' ),
                'type' => 'text',
            ),
            array(
                'id'      => 'gender',
                'name'    => __( 'Gender', 'textdomain' ),
                'type'    => 'radio',
                'options' => array(
                    'm' => __( 'Male', 'textdomain' ),
                    'f' => __( 'Female', 'textdomain' ),
                ),
            ),
            array(
                'id'   => 'email',
                'name' => __( 'Email', 'textdomain' ),
                'type' => 'email',
            ),
            array(
                'id'   => 'bio',
                'name' => __( 'Biography', 'textdomain' ),
                'type' => 'textarea',
            ),
        ),
    );
    return $meta_boxes;
}

Then go to Posts | Add New, you will see a new meta box appears below the post editor:

meta box

More fields and demos

The Meta Box plugin has a list of demos which you can use as a starting point for your projects. The list is constantly updated with the new features or new demos in every new release of the plugin.

Firstly, you should start with demo.php by downloading it here. It is basic and has all explanations in comments (please read them carefully to understand how to write the script correctly).

Here are steps to integrate the demo.php into your theme:

  • Copy demo.php file to your theme folder
  • Open functions.php file of your theme and add the following code: include 'demo.php';

Now go to Add New Post page and see the result. If everything is ok, you’ll see as the following screenshots:

Meta Box

More documentation

To customize fields and meta boxes, please look at the documentation page of the plugin. Note that the documentation is regularly updated to cover the latest features of the plugin, so keep checking it when you have any troubles using the plugin.

Grab the core extensions bundle today and save over 60%!