[wp-hackers] get attachment ID when hijacking Media Library send_to_editor

Steve Taylor steve at sltaylor.co.uk
Mon Mar 21 20:24:39 UTC 2011


Rafael, thanks for trying but I think I should have been more explicit
in my post.

The issue is about getting the attachment's ID in JavaScript, when the
"Insert into Post" button is clicked in the Media Library thickbox
interface. The send_to_editor function that it's possible to override
only receives the HTML generated ready for placing into TinyMCE (or,
in my case, placing something into a custom field) - and while it's
possible to extract image IDs from the class in the generated HTML, it
doesn't seem to be for files.


On 21 March 2011 18:58, Rafael Ehlers <rafaehlers at gmail.com> wrote:
> You are saying something like this:
>
> $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
> $img = wp_get_attachment_thumb_url( $thumbnail_id );
> echo "<img src=\"$img\">";
>
> or
>
> $thumb = wp_get_attachment_image( $thumbnail_id, 'thumbnail', true );
>
> or
>
> $attachments = get_children( array('post_parent' => $post->ID, 'post_type'
> => 'attachment', 'post_mime_type' => 'image') );
> if ($attachments) {
> $which = 'attach';
> foreach ( $attachments as $attachment_id => $attachment ) {
>  $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail', true );
> }
> }
>


More information about the wp-hackers mailing list