Forums

Update gallery thumbnails in custom field (1 post)

  1. MrMastermindNL
    Member
    Posted 1 year ago #

    Hi,

    I have a post type with a meta-box that lists all images in the gallery for that post. What I would like to do, is update that list when a new image gets uploaded to the gallery. I was hoping for an action hook that gets triggered after uploading an image, so I could then trigger my function to update the gallery list. But somehow I can't get it to work.

    this is what's in my functions.php:

    add_action('add_attachment', 'update_project_images');
    
             function update_project_images()
             {
                 ?>
                    <script type='text/javascript'>
                         jQuery('#images-meta .inside').html("<?=getAttachments()?>");
                     </script>
                 <?php
             }
    function getAttachments()
             {
                 global $post;
    
                 $attachments = & get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    
                 if($attachments) {
    
                    // Get array keys representing attached image numbers
                    $arrKeys = array_keys($attachments);
    
                    foreach($arrKeys as $iNum)
                    {
                        // Get the thumbnail url for the attachment
                        $sThumbUrl = wp_get_attachment_thumb_url($iNum);
                        $sImgString = "<img src='" . $sThumbUrl . "' width='100' height='100' \/><br />";
                        echo $sImgString;
                    }
    
                 }
             }

    Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic