Home › Forums › Add-ons › Gallery Field › Random Gallery Image with wp_get_attachment_image() › Reply To: Random Gallery Image with wp_get_attachment_image()
Cool, I see the problem with your code; you’re not passing the correct arguments to wp_get_attachment_image. It expects as a first argument an attachment ID. In your case, you’re passing the whole image array.
So instead of $images[$rand]
you should get the ID
out of this array.
wp_get_attachment_image( $images[$rand]['ID'], $size );
Panos
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.