<?php
$images = get_field('gallery');
$size="full"; // (thumbnail, medium, large, full or custom size)
$rand = array_rand($images, 1);
if( $images ): ?>
<?php echo wp_get_attachment_image( $images[$rand]['ID'], $size ); ?>
<?php endif; ?>
This code should work. array_rand()
return key if second param set to 1 or array with keys if second param > 1
Related Posts:
- ACF Wysiwyg Editor Image srcset for responsive images [closed]
- How to get both image attachment ID and url
- Srcset incorrect with Owl Carousel and ACF?
- Call the cropped image of a custom field in the theme
- Advanced Custom Fields Image Crop
- Generate / attach Image srcsets from ACF Image Field
- WP 4.4. responsive images browser choosing the “wrong” one
- WP 4.4 aspect ratio with responsive image
- How to add a custom field to quick edit
- Gutenberg First Block on Page Conditional?
- Get a list of all image sizes that match aspect ratio of original one
- Comparing arrays with meta_query in pre_get_posts
- How to order by just the Time Field in Advanced Custom Fields
- Using Gutenberg parse_blocks Function With ACF Custom Blocks?
- Random popup image per user with no repeat
- Get specific repeater row (via advanced custom fields) based on Meta Query with Wildcards [closed]
- How to update custom taxonomy meta using ACF update_field() function or any other wordpress function
- Thumbnails generated from PDF in the “Media” section – how to show them in theme template?
- How to count ACF Flexible Content Rows?
- GIF featured image is resized on server but not used in frontend. Why?
- Query between dates using date picker filter breaks in WordPress 4.2.1
- How to upload multiple images on frontend to ACF gallery using update_field
- Get ACF value after update user using save_post
- random p tag in advanced custom fields?
- How can I track and output when a field is updated? (currently using Advanced Custom Fields)
- ACF Image ID, echo the alt tag
- Add up values from ACF number field
- Advanced Custom Fields: Conditional Statement with Select
- Removing height and width from images with a caption
- Add PDF to ACF image field from file url
- Bulk-Update Custom Posts
- Group ACF repeater fields from differrent posts
- ACF Add fields values to newly inserted post [closed]
- Programatically re-order images in the ACF gallery add-on. Orderby Title, ID, etc
- Not displaying posts that are in the past. ACF date > date
- acf repeater was free in start [closed]
- Use ACF select field to add a class to div inside a flexible content layout [closed]
- One of my image sizes isn’t showing up in srcset
- srcset and custom field get_post_meta and wp_get_attachment_url
- Website goes down while importing backup (Internal server 500)
- Website loading slowly – Advanced Custom Fields images
- ACF: If field contain a specific value, update value in another field programatically
- how to load random related posts with specific custom fields?
- Add original validation rule to Advance Custom Fields
- ACF – Pick first or second value from comma separated values
- How to get ACF value inside Gutenberg Block from another page or template? I’m using Timber too
- ACF Image field not displaying in WordPress with Visual Composer [closed]
- Frontend Form Checkbox Update ACF Field
- ACF and Gravity Form file upload frontend [closed]
- Trying to select 1 item from an array
- Query and display only by first letter of the get_field value
- Sorting get_terms, ACF is automatically removing duplicates
- How to acquire an ACF image using get_previous_post and get_next_post
- Building large multi-section pages with Advanced Custom Fields
- Showing a post depending on the Custom Field value
- Advanced Custom Fields plugin : displaying a field while omitting the p tags
- Change Image Sizes for Mobile Theme
- Widget Code / Advanced Custom Fields / Elementor
- How can I apply an ACF field to a single custom post if it refers to the taxomy of that post type in the rules?
- Getting “Years Only ” from ACF Date Picker field to Hidden filed in the fields group
- How to show related post having same relationship filed under single CPT?
- Trying to update repeater field (ACF) dynamically with data from Contact Forms 7
- Update field for repeater not working
- How can i add service category here? [duplicate]
- Get title color from category custom field
- WP Cron Working, but Function Not Working
- How to get a product’s Custom Fields in a different template file?
- pre_get_posts hook not targeting search results page query
- ACF – get custom taxonomy term image field
- Populating ACF Image Fields from JSON file
- ACF group field disappeared after deployment using deployer script
- ACF Dynamic select not showing data
- Field has disappeared on post page
- Modification of RSS feed is not consistent
- Display posts every specific day
- How to use WP Backery on Wysiwyg ACF
- How to use germ_terms() with meta_query for ACF Taxonomy field?
- Looking for a javascript callback action to re-initiate a custom slideshow in gutenberg
- Hide Menu Items from guess user with ACF
- Advanced Custom Fields Gallery and Flex Slider [closed]
- Help using an array in ‘exclude’ key of another array
- Display custom image field in user profile
- Build table using Advanced Custom Fields
- Decide how Hero image appears on mobile
- Getting extra image links in code with wp_get_attachment_image
- Front page showing ACF only once, is that solvable to show the ACF per post? [closed]
- Add column and acf field content for cpt
- Can’t get ACF repeater data in category template
- ACF scheduled repeater fields
- Get the category fields even if there is no post
- Advanced Custom Fields Show After Password [closed]
- use advance custom field inside query post command [closed]
- Multiple loop issue – pull one featured and then continue the loop
- Check if meta_key exists in wp_list_pages
- ACF + WPML: How to translate date fields?
- Using ACF custom field for custom post type to order categories
- PHP calls to custom fields not being made. Query seems to be blocking them
- Custom headings on WYSIWYGs per flexible content module in ACF
- Same ACF Relationship field for multiple Post Options sub-pages?
- Pending posts showing category until published