How to reorder meta box position?

I have a custom post type which have a lot of custom field that categories in meta box. The problem is how do I sorting the meta box in the order that I desired?

As I know there is only ‘high’,’core’,’normal’ and ‘side’ for positioning the meta box, which is not a practical way to sorting the meta box. Let’s say if I set ‘high’ position for two meta boxes, how do I know which one is on the top??

Read More

Thanks

Related posts

Leave a Reply

2 comments

  1. Users can drag and drop meta boxes and WordPress will save the order. So, in a sense, the order in which they were originally rendered does not matter.

    You know which one comes first because when you call add_meta_box it simply pushes your meta box’s args onto a global array called $wp_meta_boxes. Whichever call to add_meta_box came first will be the first meta box.

  2. In the following example, replace CPT with the post type name, like post, page, book, event, imaginary, foobar…

    add_filter( 'get_user_option_meta-box-order_CPT', 'metabox_order' );
    function metabox_order( $order ) {
        return array(
            'normal' => join( 
                ",", 
                array(       // vvv  Arrange here as you desire
                    'customdiv-{CPT}',
                    'authordiv',
                    'slugdiv',
                )
            ),
        );
    }