Support » Plugin: ACF Photo Gallery Field » Get Caption Field from WP Media Section

  • Resolved FROM_ROB

    (@from_rob)


    Hello hello,
    Thank you so much for this super helpful plugin.

    I am having trouble with one small part, I would like the “Caption” Field to be linked with the “Caption” Field from the WP Media Uploader.

    Currently, in the Photo Gallery edit section, “Caption” is displaying the “Description” from the WP Media section.

    Is it possible to show the actual Caption from the attachment in the Photo Gallery edit section?

    Thank you!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Navneil Naicker

    (@navzme)

    Hi
    You can use WordPress built-in function wp_get_attachment_caption

    How to use the function?
    Wherever you want to output the caption, place the following code there.

    <?php echo wp_get_attachment_caption( $id ); ?>

    Thanks for getting back so quickly.

    I think you may have misunderstood my dilemma. The problem is happening in the Post section in the WP Admin. When I click the pencil icon on an image in the Photo Gallery, it opens the Edit box, which displays the the Title and Caption of the image, which is coming from the WP Media section.

    Although, the problem is, in the Photo Gallery Edit window, the part that is titled “Caption” actually shows the “Description” from the WP Media section.

    Is it possible for this to show the actual “Caption” from the WP Media, and not the “Description”?

    Thank you

    Plugin Author Navneil Naicker

    (@navzme)

    Hi @from_rob
    I can understand you now. I have messed this up. The caption on the edit box should be pulling WP media and not the description. The below fix will be updated in the next version of the plugin. To solve this mess urgently, you will need to replace the current plugin code with the latest code.

    Goto this link on Github. Copy all the code from that link and replace with everything on this file wp-content\plugins\acf-photo-gallery-field\fields\acf-photo_gallery-v4.php.

    After doing that, add the following line on your themes functions.php file.
    add_filter( 'acf_photo_gallery_editbox_caption_from_attachment', '__return_true' );

    Let me know
    Cheers!

    That is working, thanks so much!

    I have one final request. I would like to also have the Photo Gallery Edit section pull the Title, Caption, Alt, Description from the WP Media–just so everything can easily be updated in the post itself. I thought I could do this by making some small edits to the navz-photo-gallery.php file, although it doesn’t seem to work for the Alt and Description.

    Here is what I tried…

    function acf_photo_gallery_image_fields( $args, $attachment_id, $field){
    	return array(
    		'title' => array('type' => 'text', 'label' => 'Title', 'name' => 'title', 'value' => ($args['title'])?$args['title']:null),
    		'caption' => array('type' => 'textarea', 'label' => 'Caption', 'name' => 'caption', 'value' => ($args['caption'])?$args['caption']:null),
    		'alt' => array('type' => 'textarea', 'label' => 'Alt', 'name' => 'alt', 'value' => ($args['alt'])?$args['alt']:null),
    		'description' => array('type' => 'textarea', 'label' => 'Description', 'name' => 'description', 'value' => ($args['description'])?$args['description']:null)
    	);
    }

    What do you think is the best way to achieve this?
    Thanks so much for your help with this, it is greatly appreciated!

    Alternatively, is it possible to display the Caption text area as a wysiwyg editor?

    Something like…

    function acf_photo_gallery_image_fields( $args, $attachment_id, $field){
    	return array(
    		'caption' => array('type' => 'textarea', 'label' => 'Caption (remember to put title in between em tags and separate information with commas)', 'name' => 'caption', 'value' => ($args['caption'])?$args['caption']:null)
    	);
    }

    Although this doesn’t work.

    Thanks so much!

    Plugin Author Navneil Naicker

    (@navzme)

    Hi @from_rob
    I’m planning to include WYSIWYG editor for the caption in the future.

    For your other request to have Title, Caption, Alt, Description from the WP Media, in the coming days I’m going check alternative way to implement this.

    Hey Navneil,

    No trouble, that sounds good, thanks for letting me know. For now its no trouble to worry about implementing the Title, Caption, Alt, Description from the WP Media, since I was planning to split different part of a caption into each, although actually a WYSIWYG would solve that, so I can wait for the future release with that.

    A more urgent matter, going back to your post with the updated file to get the Caption from WP Media in the Photo Gallery Editor…

    wp-content\plugins\acf-photo-gallery-field\fields\acf-photo_gallery-v4.php.

    + in the themes functions.php file.
    add_filter( 'acf_photo_gallery_editbox_caption_from_attachment', '__return_true' );

    This is working completely fine and really well, the only thing that doesn’t work, is if I put text into the Photo Gallery Editor Caption and save it, it actually saves and updates the Description from WP Media, not the Caption in WP Media.

    Is it possible so that if the text in the Photo Gallery Editor caption is saved, it saves also in WP Media Caption instead of WP Media Description?

    This is my last request, then I’ll have everything working the way I need to.

    Thanks so much for your help, it is super appreciated!

    Hey Navneil,

    if you are able to help with this last request of the Photo Gallery Editor saving the caption in the WP Media Caption area instead of the WP Media Description area that would be amazing! it’s my last request and the only thing I’m needing to finish the site im working on.

    Thanks so much for your help!
    Rob

    Plugin Author Navneil Naicker

    (@navzme)

    Hi Rob
    Sorry, I got caught up with my day job and forgot to answer your question. Please download the latest copy of acf-photo_gallery-v4.php from this link and replace it on your current acf-photo_gallery-v4.php just like before we did.

    Please confirm.

    Thanks so much Navneil! This is working great and now it saves correctly in the Photo Gallery Editor and the WP Media caption.

    The only problem, which is quite important, is that when saving the new caption added in the Photo Gallery Editor, it removes any html tags.

    Is it possible to allow it to keep the html tags in the caption added in the Photo Gallery Editor?

    I’m using it for artwork captions and need to use it to be em tags around the title, so they are italic.

    Thanks so much!
    Rob

    Plugin Author Navneil Naicker

    (@navzme)

    Hi Rob
    WordPress saves the caption in the ‘excerpt‘ column of the database. They don’t allow HTML tags in that ‘excerpt‘ column. I don’t have a work around for this.

    Normally I would use CSS to style the title and etc.

    Hi Navneil,

    That is odd to hear, since if I add html into the WP Media Caption and save it, the html is saved and also outputted as html.

    So I imagine there must be a way for the html not to be stripped out.

    Thank you!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Get Caption Field from WP Media Section’ is closed to new replies.