Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Ankur, could you let me know what version of WordPress you’re running as well as any plugins you have that might be conflicting? I use the plugin regularly and haven’t experienced this problem on my own sites.

    Thanks, Chris!

    Thread Starter ankurm

    (@ankurm)

    Hi Chris!
    I am using the latest version of wordpress (3.5.1).

    I was able to add the custom fields to the image and was also able to fetch the data but only if I set the image as a featured image.

    My question is how can I fetch the custom field of the image which I insert into the post(not setting it as the featured image). Similarly what if i insert a few images as a gallery. How can I fetch their custom field data.

    Thanks!
    Ankur

    Hi Ankur, there isn’t a method (at the moment anyways) to associate the custom data with gallery images but there are two functions for displaying the information on your page:

    thisismyurl_get_custom_media_field( $attachment_id, $unique_field_id ) will fetch the data while thisismyurl_custom_media_field( $attachment_id, $unique_field_id ) will display it.

    Thread Starter ankurm

    (@ankurm)

    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

    Hi Chris,

    So I just cut and paste

    thisismyurl_get_custom_media_field( $attachment_id, $unique_field_id )

    thisismyurl_custom_media_field( $attachment_id, $unique_field_id )

    into my theme? I don’t need <?php at the start and ?> at the end, or anthing?

    Changing unique_field_id to what I called it?

    What’s the $attachment_id part – do I leave that as is?

    It’s all such a mystery!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘unable to work with it if i have to insert a gallery in a post’ is closed to new replies.