How to group meta boxes on the post edit page

Thanks for the hint Bainternet, indeed this is very easy to implement with jQuery. Example (the four meta boxes are closed for clarity) : Here’s what I did : var $j = jQuery.noConflict(); $j(document).ready(function() { $j(“#side-sortables”).append(‘<div id=”container_div” class=”postbox meta-box-sortables ui-sortable”><div class=”handlediv” title=”Click to toggle.”><br></div><h3 class=”hndle”><span>Container Meta Box</span></h3><div id=”container_inside” class=”inside”></div></div>’); $j(“#my_metabox_div”).appendTo(“#container_inside”); $j(“#my_other_metabox_div”).appendTo(“#container_inside”); etc… }); I added … Read more

Save checkbox value in metabox

This isn’t a WP question, but moreso a general form issue. Regardless, a checkbox will not pass anything if unchecked, and 1 or on if checked. // Sanitize user input. $my_data = $_POST[‘home_slider_display’] ? true : false; // Update the meta field in the database. update_post_meta( $post_id, ‘home_slider_display’, $my_data );

Removing meta boxes: remove-meta_box() or unset()?

When in doubt use the API. Let’s say the structure of $wp_meta_boxes will change or go away one day. remove_meta_box() will still work, because the API is a contract between core and developers. Unsetting some keys in a global variable might break. unset() is easier to write when you want to remove a whole group: … Read more

Custom Meta Boxes: multiple fields within a repeatable field

Try Fieldmanager. It was built with repeating groups being priority #1. Your new code would look something like this: add_action( ‘init’, function() { $fm = new Fieldmanager_Group( array( ‘name’ => ‘artists’, ‘limit’ => 0, ‘label’ => ‘New Artist’, ‘label_macro’ => array( ‘Artist: %s’, ‘name’ ), ‘add_more_label’ => ‘Add another Artist’, ‘children’ => array( ‘name’ => … Read more

How do I position meta_box on post edit screen after the title?

You cannot use a real metabox to do that, hook into edit_form_after_title instead. Here is a simple example: add_action( ‘edit_form_after_title’, ‘wpse_87478_pseudo_metabox’ ); add_action( ‘save_post’, ‘wpse_87478_save_metabox’ ); function wpse_87478_pseudo_metabox() { global $post; $key = ‘_wpse_87478’; if ( empty ( $post ) || ‘post’ !== get_post_type( $GLOBALS[‘post’] ) ) return; if ( ! $content = get_post_meta( $post->ID, … Read more

One metabox for multiple post types

Define an array of post types, and register the metabox for each one separately: function add_custom_meta_box() { $post_types = array ( ‘post’, ‘page’, ‘event’ ); foreach( $post_types as $post_type ) { add_meta_box( ‘custom_meta_box’, // $id ‘Custom Meta Box’, // $title ‘show_custom_meta_box’, // $callback $post_type, ‘normal’, // $context ‘high’ // $priority ); } }