Is there an explicit action hook that will fire when (or just before) the admin Edit page renders for a custom post type? Something similar to {$new_status}_{$post->post_type}?

I’m trying to find the least obtrusive place to insert my add_meta_box() registration so that it’s not calling that function on every page refresh, but only when it’s needed (ie: the user wants to create a new custom post or edit an existing custom post).

Thanks for your thoughts / code snippets!

1
1

register_post_type() has a registration option called 'register_meta_box_cb'. Set that to a valid callback and it will call that function only when it is compiling the meta boxes for that post type’s edit screen. Something like this:

register_post_type( 'foo', array(
  'public' => true,
  'label' => 'foo',
  'register_meta_box_cb' => 'bar',
));

function bar(){
  add_meta_box('blah', 'blah', /* etc */ );
}

Leave a Reply

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