Reputation: 30521
When inserting an image via media uploader into a wordpress Post, is there a way to know all the properties of that image the same way wp has global $post
which shows all properties of the post it's in?
Upvotes: 0
Views: 425
Reputation: 586
Not sure if this is quite what you mean but a WP attachment (be it an image or any other type of uploaded media) is treated as a post. Therefore you can run get_posts
to get an array of attachment objects that match your criteria. Then use a foreach
loop to display whatever data you need from these objects e.g.:
$args = array(
'post_type' => 'attachment',
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo apply_filters('the_title', $attachment->post_title);
the_attachment_link($attachment->ID, false);
}
}
You can also use any other parameters of the WP_Query class to build your query within get_posts and narrow down the attachements that you're after - you will need to specify attachement as the post type though
Resources you want to check out:
http://codex.wordpress.org/Template_Tags/get_posts
http://codex.wordpress.org/Function_Reference/the_attachment_link (also look at the related functions at the bottom)
Upvotes: 1