6

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??

Thanks

4

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.

  • I know, but I want the position to be fixed. I don't want to allow the user to change the position. Is there anyway to predefined the position by the admin, and then fixed it so the user cannot change it? – dev-jim Jul 9 '12 at 13:24
  • Why is your meta box that important? – chrisguitarguy Jul 9 '12 at 13:54
  • 5
    Well, I just want better user experience. – dev-jim Jul 9 '12 at 15:41
  • @dev-jim can you solve this questions, I want to the same functionality. best – xzegga Nov 9 '15 at 8:19
  • Maybe disabling the ability to drag it around is bad UX. Yet, what about redefining the order they are added at? Perhaps the CPT has a register_meta_box_cb in the register_post_type which will regard that metabox as first, but it would be nice to make sure that a later-added metabox can still display first by default. – Firsh - LetsWP.io Feb 3 '17 at 8:20
0

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',
            )
        ),
    );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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