Use get_children()
(Codex ref):
$images = get_children( array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC'
) );
The first image will be $images[0]
.
EDIT:
And by “first image”, I mean, the $ID
of the first image, which you can use with any of the myriad image- and attachment-handling functions in WordPress. If you can clarify what you want to do with the image, I can provide more specific, further instruction.
Related Posts:
- How do i upload an image and return the image id?
- Is there a way to get attachment data?
- Link to full size image or attachment page in photo theme
- Handling image uploads without thickbox
- Get images attached to a specific page
- WordPress Attachments with old images
- Attachments without images
- Prevent WordPress from generating medium_large 768px size of image uploads?
- how to get original image using wp_get_attachment_image_src
- Can I attach image to post without adding it to post?
- Set default image link target in Gutenberg image block
- Using Images in WordPress – Best Practices
- How to find attachment by it’s name?
- How do I detach images from posts?
- How do I delete all generated images from my server except those currently used in posts
- Theme Customiser Image Control
- Get attachment ID of author_meta image – Attachment Metadata
- Associate an existing image with a post
- Insert Images at Master Uniform Height
- How to remove title attribute from gallery links and images
- Get an image from url in front end submission form
- Open the attachment details modal
- How to upload image without post ID using the new media uploader?
- How do I delete thousands of unattached images?
- Media sizes aren’t being created – server config?
- Add visual editor to Media Edit Screen
- Regex to turn embedded images in to attachments
- Re-process Images
- custom image size with New Media Manager in wordpress 3.5
- Show prev and next post links for parent post of current image in attachment page?
- Regenerate missing _wp_attachment_metadata
- How to make programmatic image upload generate thumbnail and sizes?
- Can’t access ‘Store uploads in this folder’
- How to add qtranslate multi language support for media?
- Why can I not view image attachment pages?
- Rename media files generated during upload
- Thumbnails are bigger in size than the original image
- add the post as canonical for attachment page wordpress
- How Do I Delete All The Images from WordPress
- media_sideload_image with rewritten urls?
- image in my post disappeared after I upload website to remote server
- WordPress adds extra width to post images container boxes
- Customizing the attachement page to show rest of all images in a gallery from post
- WordPress automatically downscaled images larger that original
- How to change image atributes right before an image to be saved?
- Is it possible to change ‘Link to’ in all images in all articles?
- Ho to add “Create Slider” option to default “Add Media” popup?
- Images attached to posts from library link to 404 error page
- Help to upload post attachments from Ajax
- Edit image results in copies of file being created
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Blank upload.php page
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Export xml use/import images from theme directory
- Is it possible to change image size used for preview thumnail in Add Media popup
- Call to undefined function wp_generate_attachment_metadata()
- How do you import images from a URL in your post?
- Retrieve Image Attachments Getting Post Thumbnail Image First
- Why WordPress suddenly changed sizes of thumbnails?
- Auto delete pictures in media library by age
- How to get image URL from media_sideload_image?
- How to test if there are no more previous or next image on attachment page?
- Show last 12 uploaded images on home page, but only from posts
- Output posts attached images as thumbnails linked to full-size with lightbox class
- Serving Images from subdomain in wordpress
- User uploads image as “Featured Image” but WordPress resizes it?
- Profile image does not upload
- Allow a specific user role I have created to only upload one image to his media library
- How to display the Media Library Items Upload date
- Upload error on localhost (at minimum, not yet tested online)
- Custom image size not displaying with wp_get_attachment_image()
- Images not loading on webpage, and links to other media give 404 Not Found
- unsharp thumbnails after uploading image
- Post-processing of the image failed
- Generate links on all images in posts – is there a hook?
- Use wget to find used images
- Get “Image CSS Class” value from the Advanced Options section
- Unable to delete images in Media Library
- How to regularly backup and update WordPress website with lot of images?
- Uploaded images not showing properly using wordpress
- After I upload a file to library its name converted to dashes
- How do I display image files as links?
- attachment.php & flexslider—linking thumbnail to specific image
- Surround uploaded image link with div
- page displaying media caption shortcodes
- Setting name of attachment URL
- Show title when inserting single images
- Broken Media Library
- wp_get_attachment_link() add rel attribute if the link points to direct image
- greater flexibility in targeting images attached to page
- Stop Attachment image names from taking top level permalink
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- WordPress API, creating Featured Media from image url (nodejs)
- Delete all thumbnails & regenerate them?
- Broken images after importing posts and opening in Gutenberg
- Image Attachments Query Not Working If Post Is Loaded Via Ajax
- How to get WordPress to resize images for srcset?
- Attachment tag archive
- Uploading media to wordpress API with C# HttpClient