Skip to content

Instantly share code, notes, and snippets.

@rilwis
Last active February 19, 2016 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rilwis/b733f20369b6c282e68f to your computer and use it in GitHub Desktop.
Save rilwis/b733f20369b6c282e68f to your computer and use it in GitHub Desktop.
Register Meta Boxes
<?php
// IMPORTANT: This is depracated and not supported any more
// Global variable which stores all meta boxes.
global $meta_boxes;
$meta_boxes = array();
$prefix = 'rw_';
// 1st meta box
$meta_boxes[] = array(
'id' => 'personal',
'title' => __( 'Personal Information', 'textdomain' ),
'post_types' => array( 'post', 'page' ),
'fields' => array(
array(
'name' => __( 'Full name', 'textdomain' ),
'desc' => 'Format: First Last',
'id' => $prefix . 'fname',
'type' => 'text',
'std' => 'Anh Tran',
'class' => 'custom-class',
'clone' => true,
),
)
);
// 2nd meta box
$meta_boxes[] = array(
'title' => __( 'Media', 'textdomain' ),
'post_types' => 'movie',
'fields' => array(
array(
'name' => __( 'URL', 'textdomain' ),
'id' => $prefix . 'url',
'type' => 'text',
),
)
);
function YOURPREFIX_register_meta_boxes() {
global $meta_boxes;
if ( ! class_exists( 'RW_Meta_Box' ) )
return;
foreach ( $meta_boxes as $meta_box ) {
new RW_Meta_Box( $meta_box );
}
}
add_action( 'admin_init', 'YOURPREFIX_register_meta_boxes' );
<?php
add_filter( 'rwmb_meta_boxes', 'YOURPREFIX_register_meta_boxes' );
function YOURPREFIX_register_meta_boxes( $meta_boxes ) {
$prefix = 'rw_';
// 1st meta box
$meta_boxes[] = array(
'id' => 'personal',
'title' => __( 'Personal Information', 'textdomain' ),
'post_types' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __( 'Full name', 'textdomain' ),
'desc' => 'Format: First Last',
'id' => $prefix . 'fname',
'type' => 'text',
'std' => 'Anh Tran',
'class' => 'custom-class',
'clone' => true,
),
)
);
// 2nd meta box
$meta_boxes[] = array(
'title' => __( 'Media', 'textdomain' ),
'post_types' => 'movie',
'fields' => array(
array(
'name' => __( 'URL', 'textdomain' ),
'id' => $prefix . 'url',
'type' => 'text',
),
)
);
return $meta_boxes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment