• Resolved Eric Acampora

    (@eric-acampora)


    I have a custom post type called Testimonials with three custom metaboxes: client, company, and quote – as well as the default thumbnail metabox.

    I had originally created Testimonials with only two out of the three boxes. Now, after adding the third box, it seems I am unable to reorder them via add_metabox() functionality. The third box always appears last. Is this a database issue? Or am I missing something?

    Note that I am completely aware of users’ ability to rearrange the boxes via personal user accounts. I instead would like these boxes to have a default order to ensure pleasant user experience.

    Thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • What’s the code that you’re using to add them?

    Remember there’s two components to the position. first, there’s the $priority argument when you call add_action(), which is probably the most importnat, but if they are all called at the saem time with the same priority, the order that they are added using add_meta_box() is the order that they will display in.

    Thread Starter Eric Acampora

    (@eric-acampora)

    Thanks for your response. Here is the code:

    function awc_testimonial_meta_boxes( $post ) {
      add_meta_box(
          'client-meta-box',
          __( 'Client' ),
          'awc_render_client_meta_box',
          'testimonial',
          'normal',
          'default'
      );
        add_meta_box(
            'company-meta-box',
            __( 'Company' ),
            'awc_render_company_meta_box',
            'testimonial',
            'normal',
            'default'
        );
        add_meta_box(
            'quote-meta-box',
            __( 'Quote' ),
            'awc_render_quote_meta_box',
            'testimonial',
            'normal',
            'default'
        );
    }
    add_action( 'add_meta_boxes_testimonial', 'awc_testimonial_meta_boxes' );

    As you can see, for each call to add_meta_box(), the $context is set to ‘normal’, and $priority is set to ‘default’.

    You mentioned using same $priority for each should output the order in which they are called, but for some reason it keeps outputting…

    > Client
    > Quote
    > Company

    …even though I am calling them in the following, desired order:

    > Client
    > Company
    > Quote

    The code that you’ve got there should be setting them up in the correct order that you’re after, so just by that part there’s nothing that I can see that would move the boxes around like that. Did you change the ordering for your screens manually (drag-and-drop)? That’s the only thing that I can think of for now.

    One suggestion that I’d make is simplifying things a bit though. There’s no need for three meta boxes like that when you can have one and set up all of the fields in that one area. That way things are always going to be set out in the right order, and you’ll be cutting out the extra meta boxes that you’ve got. ??

    Thread Starter Eric Acampora

    (@eric-acampora)

    I must have moved them around manually when I was setting things up several days ago! They are outputting correctly on the fresh administrator account I just created.

    Thanks again for your help. Also, thank you for your suggestion. You just answered something else for me – that there is indeed a reason why each metabox key is attached to an array, not a single value.

    I was a bit confused when I saw that, but it all makes sense now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Reordering Custom Metaboxes’ is closed to new replies.