WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for some modules that implement add meta box as shown here perhaps with some ajax magic.

If you have any modules I could check out would be welcome.

share|improve this question
up vote 2 down vote accepted

I recently published a meta box class named My Meta Box which takes care of most of the metabox creation and data saving and that was forked out of from Meta Box script by Rilwis.

Using the class is simple eg:


if (is_admin()){
* prefix of meta keys, optional
* use underscore (_) at the beginning to make keys hidden, for example $prefix = '_ba_';
* you also can make prefix empty to disable it
$prefix = 'ba_';
* configure your meta box
$config = array(
'id' => 'demo_meta_box', // meta box id, unique per meta box
'title' => 'Demo Meta Box', // meta box title
'pages' => array('post', 'page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(), // list of meta fields (can be added by field arrays)
'local_images' => false // Use local or hosted images (meta box images for add/remove)
* Initiate your meta box
$my_meta = new AT_Meta_Box($config);

* Add fields to your meta box

//text field
$my_meta->addTextField($prefix.'text_field_id',array('name'=> 'My Text Field'));
//textarea field
$my_meta->addTextareaField($prefix.'textarea_field_id',array('name'=> 'My Textarea Field'));
//checkbox field
$my_meta->addCheckboxField($prefix.'checkbox_field_id',array('name'=> 'My Checkbox Field'));
//select field
$my_meta->addSelectField($prefix.'select_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> 'My select Field', 'std'=> array('selectkey2')));
$my_meta->addCheckboxListField($prefix.'ch_list_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> 'My CheckBox List Field', 'std'=> array('selectkey2')));
//radio field
$my_meta->addRadioField($prefix.'radio_field_id',array('radiokey1'=>'Radio Value1','radiokey2'=>'Radio Value2'),array('name'=> 'My Radio Filed', 'std'=> array('radionkey2')));
//date field
$my_meta->addDateField($prefix.'date_field_id',array('name'=> 'My Date Field'));
//Time field
$my_meta->addTimeField($prefix.'time_field_id',array('name'=> 'My Time Field'));
//Color field
$my_meta->addColorField($prefix.'color_field_id',array('name'=> 'My Color Field'));
//Image field
$my_meta->addImageField($prefix.'image_field_id',array('name'=> 'My Image Field'));
//file upload field
$my_meta->addFileField($prefix.'file_field_id',array('name'=> 'My File Field'));
//wysiwyg field
$my_meta->addWysiwygField($prefix.'wysiwyg_field_id',array('name'=> 'My wysiwyg Editor Field'));
//taxonomy field
$my_meta->addTaxonomyField($prefix.'taxonomy_field_id',array('taxonomy' => 'category'),array('name'=> 'My Taxonomy Field'));
//posts field
$my_meta->addPostsField($prefix.'posts_field_id',array('post_type' => 'post'),array('name'=> 'My Posts Field'));

* To Create a reapeater Block first create an array of fields
* use the same functions as above but add true as a last param

$repeater_fields[] = $my_meta->addTextField($prefix.'text_field_id',array('name'=> 'My Text Field'),true);
$repeater_fields[] = $my_meta->addTextareaField($prefix.'textarea_field_id',array('name'=> 'My Textarea Field'),true);
$repeater_fields[] = $my_meta->addCheckboxField($prefix.'checkbox_field_id',array('name'=> 'My Checkbox Field'),true);

* Then just add the fields to the repeater block
//repeater block
$my_meta->addRepeaterBlock($prefix.'text_field_id',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields));
* Don't Forget to Close up the meta box decleration
//Finish Meta Box Decleration

Take a look at the class-usage-demo.php file which can also be tested as a WordPress Plugin. Other options are available for each field which can be see in the 'my-meta-box-class.php' file.

And also you can see it in use in my latest plugin ShortCodes UI

share|improve this answer
Thanks, just what I was looking for. One question, how would I add a simple button with some javascript / jquery to a metabox via the api? I notice the examples all contain some kind of input field, but in my case I just want a simple button with jquery ajax that grabs the post content and posts it remotely to a service, and the box will show the result. – giorgio79 Nov 14 '11 at 14:02
you have a function named addParagraph which you can use to add anytime you want (html buttons,js code). just make sure you have the latest version of the metabox class 0.1.4 – Bainternet Nov 14 '11 at 15:05
Why fork? Rilwis classes are nice already. – kaiser Nov 14 '11 at 18:06
@Kaiser i never said anything bad about his classes i just needed so extra functionality that was missing and that is done by forking. – Bainternet Nov 14 '11 at 18:46
@Bainternet: Hi, I found that your class adds nice additions to the original class. I think it's useful. Would you want to fork me on GitHub and collaborate what you've done here? BTW, the script is now available on WP.org as a plugin, too. – Rilwis Nov 16 '11 at 5:42

I'm not exactly sure what you're asking here, but the most basic example you can get here, along with everything else there is to know about add_meta_box, complete with save code and security checks:


/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );

/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );

/* Adds a box to the main column on the Post and Page edit screens */
function myplugin_add_custom_box() {
        __( 'My Post Section Title', 'myplugin_textdomain' ),

/* Prints the box content */
function myplugin_inner_custom_box( $post ) {

  // Use nonce for verification
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );

  // The actual fields for data entry
  echo '<label for="myplugin_new_field">';
       _e("Description for this field", 'myplugin_textdomain' );
  echo '</label> ';
  echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="whatever" size="25" />';

/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
  // verify if this is an auto save routine. 
  // If it is our form has not been submitted, so we dont want to do anything
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 

  // verify this came from the our screen and with proper authorization,
  // because save_post can be triggered at other times

  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )

  // Check permissions
  if ( 'page' == $_POST['post_type'] ) 
    if ( !current_user_can( 'edit_page', $post_id ) )
    if ( !current_user_can( 'edit_post', $post_id ) )

  // OK, we're authenticated: we need to find and save the data

  $mydata = $_POST['myplugin_new_field'];

  // Do something with $mydata 
  // probably using add_post_meta(), update_post_meta(), or 
  // a custom table (see Further Reading section below)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.