[wp-hackers] Adding a meta_box to all Post Types

Justin Tadlock justin at justintadlock.com
Tue Nov 22 23:31:35 UTC 2011


Assuming you're hooking to `add_meta_boxes()`, the first parameter 
passed to your action is the post type.

add_action( 'add_meta_boxes', 'my_meta_boxes' );

function my_meta_boxes( $post_type ) {

     $post_type_object = get_post_type_object( $post_type );

     if ( true === $post_type_object->public )
         add_meta_box();
}

On 11/21/2011 12:16 PM, Dagan Henderson wrote:
> I just did this the other day, James, so good timing.
>
> Just geet a list of post types and loop through it:
>
> 	$post_types = get_post_types( array( '_builtin' =>  false ), 'objects' );  // Gets all custom types
>
> 	array_push( $post_types, get_post_type_object( 'post' ), get_post_type_object( 'page')  ); // Adds back the 'post' and 'page' types while ommitting attachments, revisions, menus, etc.
>
> 	foreach ( $post_types as $type ) {
>
> 		add_meta_box( . . . );
> 	}
>
> Happy coding!
>
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of James Laws
> Sent: Monday, November 21, 2011 6:20 AM
> To: wp-hackers at lists.automattic.com
> Subject: [wp-hackers] Adding a meta_box to all Post Types
>
> Could anyone point me in the right direction to add custom meta box to all public post types?
>
> Thanks in advance.
>
> James
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>


More information about the wp-hackers mailing list