Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Display a custom post type's media library inline on the WordPress edit page screen
<?php
define('MY_POST_TYPE', 'my');
define('MY_POST_SLUG', 'gallery');
function my_register_post_type () {
$args = array (
'label' => 'Gallery',
'supports' => array( 'title', 'excerpt' ),
'register_meta_box_cb' => 'my_meta_box_cb',
'show_ui' => true,
'query_var' => true
);
register_post_type( MY_POST_TYPE , $args );
}
add_action( 'init', 'my_register_post_type' );
function my_meta_box_cb () {
add_meta_box( MY_POST_TYPE . '_details' , 'Media Library', 'my_meta_box_details', MY_POST_TYPE, 'normal', 'high' );
}
function my_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: 400px;'> </iframe>", get_upload_iframe_src('media') );
}
@dhilditch

This comment has been minimized.

Show comment Hide comment
@dhilditch

dhilditch Sep 23, 2014

Thanks - I was banging my head against a brick wall - I've been using WPAllImport to load images into the gallery but could not get the gallery editor to appear. Your code above, integrated into my own custom post type, solved my problem.

Thanks - I was banging my head against a brick wall - I've been using WPAllImport to load images into the gallery but could not get the gallery editor to appear. Your code above, integrated into my own custom post type, solved my problem.

@Honza-B

This comment has been minimized.

Show comment Hide comment
@Honza-B

Honza-B Feb 18, 2016

That's great! but.... how can I show render it in template? Thank for answer

Honza-B commented Feb 18, 2016

That's great! but.... how can I show render it in template? Thank for answer

@MathieuLopes

This comment has been minimized.

Show comment Hide comment
@MathieuLopes

MathieuLopes Apr 27, 2016

Thanks!

Thanks!

@mavinothkumar

This comment has been minimized.

Show comment Hide comment
@mavinothkumar

mavinothkumar Aug 9, 2016

Try using
var_dump( get_attached_media( 'image' ));
inside the post area. You will get some idea :-)

mavinothkumar commented Aug 9, 2016

Try using
var_dump( get_attached_media( 'image' ));
inside the post area. You will get some idea :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment