-1

i want to display the list of all the meta boxes of each post. the global variable wp_meta_boxes would not print anything on the screen. how can i print the value of the array to get the list of all metaboxes details.

<?php
global $wp_meta_boxes;
pr(wp_meta_boxes);
?>

But the screen is empty doesn't print anything.

2
  • I'm not totally sure how this all works, but I'd guess at the very least you'd need a minimal loop to have $wp_meta_boxes set. But at first glance I'd say this is only set in edit mode anyway: it looks like each post type sets up a 'register metaboxes' handler, and that's called from do_action( 'add_meta_boxes_post', $post ); (or change 'post' in the action name to some other post type) but only in classes that start with edit, and that's what populates $wp_meta_boxes. What exactly do you want to find - the contents of a particular box for a post?
    – Rup
    Commented Dec 29, 2018 at 8:42
  • i want to get the list of all the metaboxes for all posts
    – sophy
    Commented Dec 29, 2018 at 9:05

1 Answer 1

0

All the meta boxes are kept in a multidimensional array, called $wp_meta_boxes. It will display all of the meta boxes registered for a specific screen and a specific context.

Use the following code:

function get_meta_boxes( $screen = null, $context = 'advanced' ) {
    global $wp_meta_boxes;

    if ( empty( $screen ) )
        $screen = get_current_screen();
    elseif ( is_string( $screen ) )
        $screen = convert_to_screen( $screen );

    $page = $screen->id;

    return $wp_meta_boxes[$page][$context];          
}

Now, if you want to get an array that contains all of the meta boxes that are of "normal" priority, you have to use the following code:

$dashboard_boxes = get_meta_boxes( 'dashboard', 'normal' ); 

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.