Monday, 26 August 2013

Get images uploaded to this post in popup on editor screen

Get images uploaded to this post in popup on editor screen

I'm using the ZillaSortcodes plugin and add some functionality to build a
shortcode to use the images uploaded to the post/page for an image grid.
In the shortcode.class.php of ZillaShortcodes I use this code to retrieve
all images uploaded to the post
$referer = parse_url($_SERVER['HTTP_REFERER']);
preg_match('/post=(\d+)&/', $referer['query'], $referedID);
$actual_post = $referedID[1];
$attachments = get_posts( array(
'post_parent' => $actual_post,
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order',
));
To get the post ID I have to be a little bit tricky and getting the ID
from the URL. This works fine if the post/page is already saved and the
shortcode popup looks like this.
But this only works if the post is saved and there is a ID within the URL.
Similar to the WordPress Media Manager where I can select "Uploaded to
this post" I'm looking for a solution to get this to work even if this is
a new post.
Thanks for any tips

No comments:

Post a Comment