As far as I know get_field()
function will return the response according to the current post (There’s no need to specify the post ID). But if you want to specify the post ID then you have to type it in the second argument, like:
get_field( $selector, $post_id );
So your code would be like this:
<?php
global $post;
$post_id = 0 !== $post->ID ? $post->ID : false;
$images = get_field( 'gallery', $post_id );
if ( $images ): ?>
// Your content.
<?php endif; ?>
Do not use $post->ID
directly in the second argument because the value might be 0
sometimes if WP_Query fails. If that happens use false
to target the current post.
Check the resources:
Related Posts:
- How do I change/modify the_post_thumbnail(); html output?
- What’s the best way to use the Featured Image for responsive web design?
- How to add a class to the attachment images
- How do I hook into WordPress to save an uploaded photo as an alternate size to an existing photo?
- How to check if image is already stored in a site’s post database? (network)
- Adding a custom image upload size and making it selected by default?
- Hide custom image sizes from media library
- Change the filename format of saved featured images
- How to draw media details for Isotope gallery using Photoswipe
- How to register images uploaded via FTP in media library?
- Create Image Uploader for Widget
- Using file_exists to check file in Uploads
- Permanently remove first image from posts
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- Rename image uploads with width in filename
- Admin Media grid view images won’t load
- WordPress remove EXIF Data from specific Thumb
- Debugging upload problem: What part of WP does actual image-resizing?
- How to resize image on client-side before upload?
- Adding Featured Image to Post programatically
- Add custom image sizes to media uploader
- Conditional Statement – check if post has an attachment image
- How to upload imagick resource to media in wordpress
- Use Filename for Alt and Title Tags
- Change Width of Featured Image Thumbnail on Add/Edit Post Page
- Get a Page’s attachments in Gallery order
- Use Timber/Twig to pull an image by image ID [closed]
- Adding graphics to 404.php page
- How do I get images (with a thumbnail preview) to show in search results?
- How to get custom image size for image uploaded in Customizer
- Add custom HTML to posts page
- Strip Image Classes from HTML Output
- Additional image sizes are not being generated
- Using wp_get_image_editor in a standalone script
- Adding a querystring to an image URL when clicking ‘insert into post’?
- Assign a picture URL to a page via PHP
- How to insert a local image with custom size
- Change logo based on incoming domain
- Styling images coming from another blog
- How to scale image with equal width and height without distortion?
- Theme currently showing thumbnails, how to show full size?
- Validate Uploaded Image using WordPress’ Built-in Functions?
- Get most recent media upload
- IMG src weird behaviour inside a single post loop
- Convert all images to PNG on file upload
- Escape post image attachments added to template
- How to create an unordered list of images separate from the content
- Get the image title and alt from custom query
- How to include different html tags in the header for different pages?
- How to always display full size image
- what’s the syntax for if the image exists get the image?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Retrieving specific images from Media Library
- How do I routinely extract the thumbnail of the most recent post?
- How to change this internal image link parameter using PHP?
- add class to background image
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- Pass php to database in JQuery: With AJAX?
- How to resize an image server-side before upload?
- Creating image gallery in wordpress
- Retrieve first image url from custom post with pagination
- Image limit from 1 to 5
- Name Input from widget displays Sidebar name instead of saved data
- Gallery requires a featured image but does not show it in posts/pages
- Snapshot Theme from WooThemes — empty ‘alt’ attribute
- Changing 2011 theme header image based on user dropdown
- Setting post thumbnail sizes in template file and functions.php
- images in wordpress themes
- Determine if only one image attached to a post/page
- How to use custom fields to replace top-level parent title with an image using wp_list_pages?
- Crop images in both sides on wordpress [duplicate]
- upload images on front by user using form
- How do I return an image from a script
- PHP-Code inside Href-Tag
- HTML in PHP problem [closed]
- Adding slides to an existing carousel manually
- Where to store the images of a custom WordPress theme?
- Display Post Titles on top of the_post_thumbnail()
- add if statement to the featured image
- An automatic way to crop images of different sizes
- How to remove the intro animation which appears during the load up of some WordPress themes? [closed]
- How to automatically convert images to WebP on WordPress?
- Remove default Image Sizes
- Understanding responsive imagery
- WooCommerce: write featured image dimensions to custom fields in product’
- Generate and upload screenshot as featured image for user-submitted post
- bloginfo url in javascript
- Use URL query string in img src attribute
- Add/alter image attribute before render
- How Create Automatically Image jpg.webp from image .jpg without delete or change original images upload
- Using Featured Image as Hero Background in Word Press
- How can add alt tag in following code. Image are showing dynamic in wordpress
- Adding caption to all images inside an article
- How to add a shortcode for an image in the following function
- HELP PLEASE PHP slider css
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- Image alt tag is showing post title instead of Alt Text
- Responsive images, per image type?