Priority of Meta Box for Custom Post Type

All we need is an easy explanation of the problem, so here it is.

I’m having a small issue with the custom post type entry screen. I’d like to bump up my metabox right under the content box, but I’m not sure if that’s even possible (as the metaboxes in between are “defaults”, i.e.; Excerpt, Discussion & Author).

I’m applying the standard code:

function ctp_admin(){
add_meta_box('cpt_meta', 'Meta Box', 'cpt_meta', 'cpt_function', 'normal', 'high');
}

Thank you!

Noel

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Where you have the parameter ‘normal’ eg. the context parameter change that to read ‘core’.

add_meta_box('cpt_meta', 'Meta Box', 'cpt_meta', 'cpt_function', 'core', 'high');

The default meta boxes are registered as core and are listed first, followed by the ‘normal’ context. The docs don’t actually say you can do it but I have done without any problems.

EDIT:
Make sure your function is registered on the ‘add_meta_boxes’ hook with a high priority eg:

function my_metabox() {
    ...
}
add_action( 'add_meta_boxes', 'my_metabox', 1 ); // priority 1

The use of ‘core’ vs. ‘normal’ may not actually make a difference in the latest version.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply