I am trying to create a post type which only displays the Media Library Inline.

I have got the example from this : https://gist.github.com/897503

However, nothing happens when I click "Insert Gallery". The code is as below.

Thanks in advanced!

add_action( 'init', 'create_post_type_gallery' );
function create_post_type_gallery() {
 $args = array(
  'labels' => post_type_labels( 'Gallery', 'Galleries' ),
  'public' => true,
  'publicly_queryable' => true,
  'register_meta_box_cb' => 'my_gallery_meta_box',
  'show_ui' => true, 
  'show_in_menu' => true, 
  'query_var' => true,
  'rewrite' => true,
  'capability_type' => 'post',
  'has_archive' => false, 
  'hierarchical' => false,
  'menu_position' => null,
  'supports' => array('title','editor' )

register_post_type( 'gallery', $args );

function my_gallery_meta_box () {
  add_meta_box('gallery_details' , 'Media Library',     'my_gallery_meta_box_details', 'gallery', 'normal', 'high' );

function my_gallery_meta_box_details () {
  global $post;
  $post_ID = $post->ID; // global used by get_upload_iframe_src
  printf( "<iframe frameborder='0' src=' %s ' style='width: 100%%; height: 500px;'>   </iframe>", get_upload_iframe_src('media') );
  • This is absolutely incomplete. Example: width: 100%% and the function post_type_labels() doesn't exist in core - you should get an error there. – kaiser Jan 15 '12 at 19:55
  • post_type_labels function is created by me. No problem with that function. I am guessing the width is just part of css styling, should not be an issue – Jack Jan 16 '12 at 4:49
  • Btw, the code above works! Just add 'editor' also in the supports. – Jack Jan 16 '12 at 13:17
  • Yes. I was talking about the double %-character. – kaiser Jan 16 '12 at 15:06

Take a look at my Gallery Metabox plugin to see how to build one, or you could just use the plugin itself. There's a filter for specifying the post types it applies to.

|improve this answer|||||
  • Thanks. Plugin is cool. Anyway, the code above I pasted also does work :) My mistake on not allowing the editor. – Jack Jan 16 '12 at 13:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.