Custom meta box not showing on custom post type [on hold]

I’m trying to add a custom meta box that will appear on a custom post type. I’ve followed various examples online using add_meta_box, but the box does not appear, either when editing posts of that type or creating new ones. It does not show in screen options either. Here is my code:

class WC_Memberships_Mailchimp_Status_Sync {
/**
* Construct the plugin.
*/
public function __construct() {
add_action( ‘plugins_loaded’, array( $this, ‘init’ ) );
}
/**
* Initialize the plugin.
*/
public function init() {
// Hook to add membership plan meta box
add_action(‘add_meta_boxes’, array($this, ‘add_membership_plan_meta_box’));
}

public function add_membership_plan_meta_box() {
add_meta_box(
“mailchimp-status-integration”,
esc_html__(“Mailchimp status sync”),
array($this, ‘sync_meta_box_content’),
“wc_membership_plan”,
“normal”,
“core”
);
}

public function sync_meta_box_content( $object ) {
echo ‘Testing.’;
}
}
$WC_Memberships_Mailchimp_Status_Sync_Plugin = new WC_Memberships_Mailchimp_Status_Sync( __FILE__ );

I know the code is all running. When I add an echo statement in the add_membership_plan_meta_box function, it shows in the admin panel. Furthermore, I’ve even tried dumping the $wp_meta_boxes variable, and I see my meta box listed in there, like so:

array(1) {
[“wc_membership_plan”]=>
array(1) {
[“normal”]=>
array(1) {
[“core”]=>
array(1) {
[“mailchimp-status-integration”]=>
array(4) {
[“id”]=>
string(28) “mailchimp-status-integration”
[“title”]=>
string(21) “Mailchimp status sync”
[“callback”]=>
array(2) {
[0]=>
object(WC_Memberships_Mailchimp_Status_Sync)#623 (0) {
}
[1]=>
string(21) “sync_meta_box_content”
}
[“args”]=>
NULL
}
}
}
}
}

But it simply doesn’t show on the editor page. I’ve tried all different combinations of the last two arguments. For the callback, I’ve tried the object-style callback seen in the example code, as well as non-object style function references and an anonymous function. I’ve also tried hooking admin_init instead of add_meta_boxes, though as I said my function to add the box is being called in both cases, so I don’t think that’s it. The last thing I tried was moving this code from a plugin file to the theme functions file to see if it worked there. It did not.

Read more here:: Custom meta box not showing on custom post type [on hold]

Leave a Reply

Your email address will not be published. Required fields are marked *