Wordpress默认具有以下帖子类型,您的自定义帖子类型添加在数组的末尾:
Array
(
[0] => post
[1] => page
[2] => attachment
[3] => revision
[4] => nav_menu_item
[5] => ...all your custom post types
)
因此,您可以循环浏览它们,只需为每个帖子类型添加一个元框。注意:这不适用于
attachment
,
revision
和
nav_menu_item
, 所以你想跳过它们:
function wpse44962_add_meta_boxes()
{
foreach ( array_keys( $GLOBALS[\'wp_post_types\'] ) as $post_type )
{
// Skip:
if ( in_array( $post_type, array( \'attachment\', \'revision\', \'nav_menu_item\' ) ) )
continue;
// You\'ll have to set $id, $title, $callback yourself:
add_meta_box( $id, $title, $callback, $post_type, \'advanced\', \'default\' );
}
}
add_action( \'add_meta_boxes\', \'wpse44962_add_meta_boxes\' );