So there are several ways images can be “related” to post:
- When you upload image in post context that post is set as its parent (that is parent field of image attachments post has post’s ID).
- When you set image as a featured on a post (or use similar functionality from custom fields frameworks) the post records image attachment’s ID in it its meta.
- When you insert image into post content, the details of image attachment’s post are used to produce the markup.
Out of these the third one is the weakest to work with by code. If the only established link is the HTML markup with the URL to image then it is challenging to parse it out and reverse into meaningful ID. Not impossible, but it’s a mess.
If you have very specific use case like single image associated with the post for special purpose, then you should be using featured images or similar approach to work with IDs.
Related Posts:
- Converting a simple plugin to be placed inside of functions.php
- How to change ID of an attachment in wp_posts and its related tables correctly?
- Converting Attachment to Images?
- Get the url of the full sized attachment image using post ID?
- Search by Attachment ID
- Get all image in media Gallery with alt/title?
- How to force regenerate thumbnails in WordPress posts?
- How to show post attachment image
- wp.media.view.ImageDetails – Save settings as HTML5 data-* attributes for image
- how to get path to images in the uploads folder to be used in a plugin
- Display (and manage) webcam images?
- Cropping, Re-sizing and Saving images from one folder to another folder in wordpress
- Automatically Import Image into Posts from URLs on the Web?
- Moving image attachment from post to another?
- WordPress wp-json API – Custom Post Type returns 403
- How do I change the description of the same image which is to be found in multiple instances?
- How to select featured images for 1500 posts?
- Is there a plugin that allows a user of your site to get an email from you with an attachment?
- How to extract images of post and pages excluding header and logo image in wordpress?
- How to get all attachment image from post ?? WordPress
- How to get custom field image url of specific size
- How can i change an image’s author?
- Generated Images sizes do not match Media Settings Image Size
- How to get CMB2 to show a single image at a specific size
- How to change Thumbnail size of next Gen Gallery plugin?
- Set WordPress Featured Image For All Post Slugs Matching Image File Name in Specified Directory
- How do I create a full-bleed background image on text mouseover? [closed]
- Is it possible to insert images directly from the server?
- How to add css class to a specific set of images?
- How do I make images clickable so as to enlarge them using lightbox?
- Adding Attachment Display Settings in custom media frame
- How to replace or display the special characters from JSON API plugin [closed]
- Advanced Custom Fields
- Randomize attachment IDs
- Why isn’t “background-image: url”working with Bootstrap carousel on WP?
- Find unused images?
- How to generate video out of images via WordPress plugin
- Image gallery plugin [closed]
- How to upload images to WP Panel keeping correct folder in FTP
- Inserting HTML tag with ACF into shortcode
- Limit Number of Taxonomy Terms (Images) Displayed
- How can I implement an Add to Collection function on my Image Gallery to be downloaded later?
- Howto accurately position images with maximum flexibility?
- Show an image in my header.php
- How can I restrict image upload dimensions for non-admin WordPress users?
- Add padding while generating thumbnail
- Can we have an ‘Update metadata’ button in Image Gallery for all image instances?
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- Adding (image) caching to my Tumblr widget
- Image Manager Plugin [closed]
- Slider/text combination plugin
- Adding Static Image to WooCommerce Content-Single-Product template
- How do I get a post author’s image/avatar via RSS from another blog?
- In Woocommerce theme need to add custom external link [closed]
- How to create WordPress custom end point with multiple parameters?
- Skewed / slanted button within elementor [closed]
- Plugin for an interactive image? [closed]
- How to fix broken media library?
- How to accept images at multiple sizes and aspect ratios and display as standardized image size / ratio?
- How to get images using taxonomy ( WP Media Folder)
- adding Adsense’s In-Article Ads between images of blog post
- Add “Featured Image” box in my plugin post page
- Image Galleries for website migrated from .com to .org
- Some images on WordPress site are suddenly gone
- Regenerate Thumbnails Plugin successfully updated my thumbnails but image src won’t change to new image size?
- Multiple images per post – Show random image elsewhere
- Replace image urls(absolute instead of relative) by using filter in single page
- Looking for a photo management solution
- Simple sildeshow/image-upload plugin?
- Elementor Pro display featured image on section -> style -> image using shortcode
- Can export gallery but can’t import it Wp all import
- how to remove share button from image overlay
- How to hide featured images of all posts falling under the same category in wordpress?
- Upload Image with a file URL and show dynamically on Frontend
- submit two file input fields in the same form
- insert og image link in wordpress post
- How do I add a medium to the WordPress database with my own plugin?
- Display Multiple Photos as Featured Image when mouse moves on to it post
- How to Upload images to a custom folder in upload folder using media uploader
- what functions to use to resize images and create DB metadata for them after/during upload?
- Product Page loads terribly slow when product gallery images are added
- WordPress how do I change images used in plugins?
- Help finding a plugin – masonry type post grid
- How to wrap image tag into div for post only?
- Does WordPress have a way of changing the ‘Natural’ size of uploaded images?
- Theme Load Error
- how to open image gallery in a post/page?
- JSON Feed on my wordpress Blog
- Server Path Information
- Determine if get_the_image has image on Get the image Plugin
- Display alt text as tool tip on page
- How can I manage the background image of a slider based on the featured image of a page?
- getting image alt text via ACF plugin in WordPress [closed]
- Allow users to download media files directly from Amazon S3 (AWS plugin)
- How should I force WordPress to give proper name for the uploading images?
- How to display multiple images in the before and after plugin?
- How to Add a Website Background Image to One Page?
- Want to show pop up image on home page every time when i refresh it [closed]
- how to embed a crop feature for cropping images uploaded by the user
- How do i display the number of images on the “post screen”