Home › Forums › Add-ons › Gallery Field › Use files in Gallery field
I wanted to know if there were indications against using files (zip, ppt, pdf, doc, …) in the gallery field?
Knowing that I will only use the name and the url of the file.
Indeed, the file field (combined with a repeater field) allows to select one file at a time and “weighed down” the interface. (30 files = 30 lines, for example)
Well, it would cause problems because it will try to return an array of images. On the other hand, if you used the code at the bottom of the gallery doc page http://www.advancedcustomfields.com/resources/gallery/ “Create a WP gallery” this returns an array of attachment ID values and you could use those with
wp_get_attachment_url(). However, I’ve never tried to add files to a gallery field, have you? Will it allow files that are not images?
Here is my application:
<?php $files = get_field('files'); foreach( $files as $file ): ?> <li> <a href="<?php echo $file['url']; ?>"> <?php echo $file['title']; ?> </a> </li> <?php endforeach; ?>
It works (see attachments), but I don’t know if it will eventually produce errors afterwards.
It is most likely causing warnings in the background. I’m pretty sure that when the gallery is retrieved it uses the php function getimagesize() and using this function on non image files usually causes warnings. They generally won’t be a problem unless you turn on error display.
So if I do not have a displayed error, I can use this solution? 🙂
I don’t see why not, I would probably return it as an array of ID values and get the attachment urls myself, but that’s because I don’t like warnings.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.