1

Our website has an open system for contributors (WP User Role) to add news and calendar content to the site.

I'd like to set and lock the position of the content and meta boxes on the post edit screen. Is there a filter or function to set the order of the boxes before I disable the option of changing the sort order?

For Example, I'd like my post edit screen to appear in one column - Title > Taxonomy > Body > Meta Box > Meta Box > Publish.

2 Answers 2

2

Found this while trolling the internets... Works Perfectly

add_action('admin_init', 'set_user_metaboxes'); //I want it to fire every time edit post screen comes up
//add_action('user_register', 'set_user_metaboxes');  //You can also have it only set when a new user is created

function set_user_metaboxes($user_id=NULL) {

  //These are the metakeys we will need to update  
  $meta_key['order'] = 'meta-box-order_events';
  $meta_key['hidden'] = 'metaboxhidden_events';

  //So this can be used without hooking into user_register
  if ( ! $user_id)
    $user_id = get_current_user_id(); 

  //Set the default order if it has not been set yet by the user. These are WP handles
  if ( ! get_user_meta( $user_id, $meta_key['order'], true) ) {
    $meta_value = array(
        'side' => '',
        'normal' => 'events_metabox,submitdiv, commentsdiv',
        'advanced' => '',
    );
    update_user_meta( $user_id, $meta_key['order'], $meta_value );
  }

  // Set the default hidden boxes if it has not been set yet by the user
  if ( ! get_user_meta( $user_id, $meta_key['hidden'], true) ) {
    $meta_value = array('postcustom','trackbacksdiv','commentstatusdiv','commentsdiv','slugdiv','authordiv','revisionsdiv','postexcerpt','postimagediv','tagsdiv-post_tag');
    update_user_meta( $user_id, $meta_key['hidden'], $meta_value );
  }

 }//#end
1
0

For custom post types it works great...

add_action('admin_init', 'set_user_metaboxes');
function set_user_metaboxes($user_id=NULL) {

    // These are the metakeys we will need to update
    $meta_key['order'] = 'meta-box-order_event';
    $meta_key['hidden'] = 'metaboxhidden_event';
    $brand_meta_key['order']='meta-box-order_brand';
    $venue_meta_key['order']='meta-box-order_venue';
    // So this can be used without hooking into user_register
    if ( ! $user_id)
        $user_id = get_current_user_id();

    // Set the default order if it has not been set yet

        $meta_value = array(
            'side' => 'submitdiv,formatdiv,categorydiv',
            'normal' => 'postimagediv,event_type,eventfeaturedbrand,event_details,description_sectionid',
            'advanced' => '',
        );
        $brand_meta_value = array(
            'side' => 'submitdiv,categorydiv',
            'normal' => 'postimagediv,product_type',
            'advanced' => '',
        );
        $venue_meta_value = array(
            'side' => 'submitdiv,categorydiv',
            'normal' => 'venue_post_details,postimagediv',
            'advanced' => '',
        );
        update_user_meta( $user_id, $meta_key['order'], $meta_value );
        update_user_meta( $user_id, $brand_meta_key['order'], $brand_meta_value );
        update_user_meta( $user_id, $venue_meta_key['order'], $venue_meta_value );

    // Set the default hiddens if it has not been set yet
    if ( get_user_meta( $user_id, $meta_key['hidden'], true) ) {
        $meta_value = array('postcustom','trackbacksdiv','commentstatusdiv','commentsdiv','slugdiv','authordiv','revisionsdiv');
        update_user_meta( $user_id, $meta_key['hidden'], $meta_value );
    }
}
1
  • 2
    Please explain your code, rather than simply post it.
    – s_ha_dum
    Commented Apr 30, 2014 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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