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
- Add padding while generating thumbnail
- Can we have an ‘Update metadata’ button in Image Gallery for all image instances?
- Retrieving Meta from Image Attachment
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- Make change in media library affect images in published articles
- Adding (image) caching to my Tumblr widget
- How to upload multiple files/images when developing a wordpress plugin?
- Image Manager Plugin [closed]
- Implementing an image hosting website using WordPress? [closed]
- Bulk Image Upload And Rerrange Functionality
- Redirect to another page using contact form 7? [closed]
- How to apply lazy loading in background images [closed]
- Woocommerce showing images blurry in description page
- Slider/text combination plugin
- Plugin to hide image in excerpt
- Image change on hover
- How to write “alt” tag in image for wordpress code?
- 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]
- Getting taxonomy images to display on single-post with their terms
- Photo Gallery Plugin and Touch Devices
- Image crop, resize and compression plugin?
- How to Resize the Custom Post Images?
- Plugin that will let me specify a number of image sizes?
- How to limit image size for the entire website ? But without editing the post (css/plugin?!)
- How to create WordPress custom end point with multiple parameters?
- Images under 1MB are not being compressed
- Skewed / slanted button within elementor [closed]
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- Plugin for an interactive image? [closed]
- Clear out old images, any advice?
- 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
- Large amount image data transfer
- Blurry images when loading the page first time
- Get Image Having the ID [closed]
- Image Galleries for website migrated from .com to .org
- Best way to retrieve data in custom api extended from wp-api
- Overwrite add_image_size defined by theme
- Scrape a webpage for image and add it to post
- How do I link an image in my plugin so it displays on WordPress?
- Fetch CSS of posts
- Attachments broken after giving WordPress its own directory
- 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?
- “After file loaded” action
- Add_image_size not generating correct size
- Is there a way to insert multiple images into a post at the same time without using a gallery?
- Is there a Image Gallery which will load all my posted Images like twitter’s image grid?
- 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
- I’m having several WP issues, especially with missing images
- Simple sildeshow/image-upload plugin?
- Elementor Pro display featured image on section -> style -> image using shortcode
- Offer Download Links for Product Images
- 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?
- Bulk Image Resize for Media Library, but for ENLARGING instead of Shrinking
- Optimal image size for wordpress?
- Copy/paste local images not working in WordPress
- Upload Image with a file URL and show dynamically on Frontend
- How to add height and width to images on a page(using WP Bakery) to improve Google’s CLS score?
- Is classical wordpress eidtor a good option for me to include a large table with a large number of images on my webpage?
- Enlarge an image slider when click
- submit two file input fields in the same form
- insert og image link in wordpress post
- WordPress built-in compression of images? How well does it compare to Photoshop or Shortpixel?
- How do I add a medium to the WordPress database with my own plugin?
- Is there a way to auto generate poster image for videos
- Optimise wordpress database using SQL after deleting registered images from Media Folder
- Display Multiple Photos as Featured Image when mouse moves on to it post
- Do images in plugins automatically load?
- How to Upload images to a custom folder in upload folder using media uploader
- I need to register and resize images, safe to delete plugin afterwards?
- Displaying all the images from all of my articles
- 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
- WP_get_image_editor resizing images in a foreach loop
- WordPress create thumbnails on demand
- WordPress how do I change images used in plugins?
- Implementing Scrollable Images
- Remove special characters from filenames
- Why is my site still showing insecure icon even if I have SSL certificate?
- Looking for Image Slider that is based on default WP Media Library
- Uploading images to custom table
- Help finding a plugin – masonry type post grid