When I call global $wp_meta_boxes; it returns null. I'm trying to calling like:

class my_class()
   public function __construct(){
     add_action( 'wp_dashboard_setup' , array( $this , 'my_meta_boxes' ));
   public function my_meta_boxes(){
      global $wp_meta_boxes;
      return $wp_meta_boxes;

The class is working fine, but I cannot make it work.


To make understand better the issue, my objective is the one actually answered in this question:

I need to retrieve metaboxes for specific admin pages. The problem is that the globalis not working for me.

I appreciate any suggestion.

  • Hmm, and what exactly do you mean by "cannot make it work"? What are you expecting to do exactly? – Krzysiek Dróżdż Nov 10 '18 at 9:14
  • I'm trying to get the default WP metaboxes like "At a Glance" etc. Any Ideas? $wp_meta_boxes should have those right? – huraji Nov 10 '18 at 9:28
  • It depends on the context in which you are calling it. If the default metaboxes aren't registered, then you can't access them. Generally speaking, you should never touch these global variables directly. – fuxia Nov 10 '18 at 9:41
  • Thanks @fuxia, I know that I shouldn't but my question is then how to get those in the WP dashboard? Is there another way? I couldn't find other solutions. – huraji Nov 10 '18 at 13:21
  • $wp_meta_boxes contains the dashboard widgets when I inspect it on the wp_dashboard_setup hook. Your code isn't testable as-is, so I can't say what you're doing differently. – Milo Nov 10 '18 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.