1

I would like to add a meta box underneath the title, but before the editor on a page post type in admin. I can add it to a post, but not to a page and I don't understand why.

I've used this to add a new context that will appear under the title.

function buddydev_create_new_metboax_context( $post ) {

do_meta_boxes( null, 'custom-metabox-holder', $post );
}
add_action( 'edit_form_after_title', 'buddydev_create_new_metboax_context'  );

This works fab on a post, but if I try to add it to the page post type the metabox displays beneath the text editor, not above it.

Here is my metabox code.

add_action( 'add_meta_boxes', 'at_titles_meta_box' );

function at_titles_meta_box($post){
add_meta_box('at_meta_box', 'Add Title', 'titles_meta_box', array('page'), 'custom-metabox-holder');
}

add_action('save_post', 'at_save_metabox');

function at_save_metabox(){ 
global $post;
if(isset($_POST["tagline"])){
    //UPDATE: 
    $tagline = $_POST['tagline'];
    $sub = $_POST['sub'];

    //END OF UPDATE
    update_post_meta($post->ID, 'tagline', $tagline);
    update_post_meta($post->ID, 'sub', $sub);   
}
}

function titles_meta_box($post){
$tagline = get_post_meta($post->ID, 'tagline', true); 
$sub = get_post_meta($post->ID, 'sub', true);

?>   

<p>
<label for="tagline">Banner Strapline:</label>

<input class="widefat" type="text" name="tagline" id="tagline" value="<?php echo esc_attr( get_post_meta( $post->ID, 'tagline', true ) ); ?>" size="30" />
<br /><br />
<label for="sub">Intro Section Title:</label>

<input class="widefat" type="text" name="sub" id="sub" value="<?php echo esc_attr( get_post_meta( $post->ID, 'sub', true ) ); ?>" size="30" />
</p>

<?php
}
2
  • You could just add your metabox content into that filter and test against get_current_screen() to ensure your on the correct post type.
    – Howdy_McGee
    Commented May 12, 2016 at 15:58
  • I don't think you understand what I mean. The metabox does appear on the page post type, but in the wrong place. I've tried using the get_current_screen(), but it didn't make a difference
    – MrFox
    Commented May 12, 2016 at 16:10

1 Answer 1

1

There is user settings (user metadata) which override the initial meta box order. So it is up to user which meta box he want to display first. User can drag and drop metaboxes and arrange them in any order which he want regardless the order you've defined.

You can go to user meta table and find key with name meta-box-order_{post_type} e.g. meta-box-order_page delete the value of this key then check again.

There is nothing wrong with your code.

0

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.