Order of multiple meta boxes on a page

Support General Order of multiple meta boxes on a page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9627

    I noticed that if there are multiple meta boxes on a page, it is possible to drag the meta boxes inside the post editor to reorder them on the edit screen. Is it possible to get that ordering information in the page template, so that the order of the meta boxes on the edit screen matches the order in which they appear in the page template on the front end?

    For clarity, let's assume:

    • I have "Box A" and "Box B" in the editor. These are separate meta boxes defined with separate IDs in separate files.
    • My page template is set up to display (in order) "Box A" followed by "Box B".
    • I reorder the meta boxes on the edit screen so that "Box B" now appears above "Box A",

    Right now, the order of meta boxes on the front-end is still "Box A" followed by "Box B".

    Is it possible to know the order of these meta boxes on the backend so, in this scenario, the order of meta boxes on the front-end changes so that "Box B" is now above "Box A"?

    Thank you!

    #9633
    Anh TranAnh Tran
    Keymaster

    Hello,

    When you reorder meta boxes in the edit screen, the order is saved in the user meta called meta-box-order_$posttype. So, to get that order, you need to run:

    $order = get_user_meta( get_current_user_id(), 'meta-box-order_yourposttype', true );
    var_dump( $order );

    See this answer on WPSE for some other info:

    https://wordpress.stackexchange.com/q/70204/2051

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.