Hi Chris,
Your functions worked perfectly but we can’t get $attachment_id of the images if they are inserted into the post.
I found a way through which I integrated your plugin to the gallery feature. Maybe you could add this functionality to your plugin.
What I did was-
I observed that by using the gallery shortcode, I could get the attatchment_id of all the images. eg : [gallery ids="6500,6501"]
where 6500 and 6501 are the attachment ids of the images whose custom fields(that I created which your plugin) I wanted.
So I decided to modify the gallery shortcode itself.
This is what i wrote in my function.php file
/* Editing shortcode for Gallery */
remove_shortcode('gallery', 'gallery_shortcode');
add_shortcode('gallery', 'gallery_shortcode_fancybox');
function gallery_shortcode_fancybox($attr) {
.....
copy all the code from wp-includes/media.php which is inside the function gallery_shortcode()
.....
}
After adding this to my functions.php, I was able to create my custom gallery shortcode without modifying the core files.
In between the function, where I needed to fetch the custom fields, I added this.
/* MY CUSTOM EDITS */
$work_status = strtolower(thisismyurl_get_custom_media_field( $id, 'my_unique_id' ));
$output .= "<{$itemtag} class='gallery-item ".$work_status."'>";
$output .= "<{$icontag} class='gallery-icon'>".$link."</{$icontag}>";
/* MY CUSTOM EDITS Ends here*/
I was able to attach a class which I required.
Hope this helps you integrate your plugin with the gallery feature of the wordpress.
Thanks,
Ankur