You do not add image attachment to post. In WordPress image attachment is also post. See post types in Codex.
-
what is usually called post on surface is technically post of
post
post type. -
image attachment is a post of
attachment
post type.
So what you need to do is to create image attachment (using wp_insert_attachment()
and couple more related functions) and set your post as parent for it.
Related Posts:
- changing the default picture size link url
- How To Retrieve An Image Attachment’s Alt Text?
- getting attachement images src and add classes
- Check if post has attachments (not image)
- Validate alt text for attachments?
- Applying automatic link class to images embedded to posts
- Detect if is image unattached
- Retrieving a custom link on an attachment
- how to test for attached image
- get post attachments of a particular size
- How to remove title attribute from gallery links and images
- Change image link: wp_get_attachment_link
- Gel all image from certain post type
- Making images from single.php pointing to an attachment .php template
- ID of images from gallery
- wp_get_attachment_image_src always returns false
- Exact image sizes
- Get the size (size in Kb or MB) of an featured image?
- Get a Page’s attachments in Gallery order
- Hide “Gallery Settings” and “Insert into Post” button from Attachment window
- query attachment images … if no attachments -> get attachments of parent page?
- Getting attachment images is cloning some of them
- Edit default image attachment size
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Reorder “menu order” of attachments to another predefined order
- Change code to display image attachment page
- Attachment 0×0 size error [closed]
- Removing width and height attributes from wp-get-attachment
- Get post attachment images dimension and use in embed code
- use wp_get_attachment_image() to show attachments
- Ordering of gallery images without using shortcode in theme
- Adding width and height to wp_get_attachment_image_src
- Get the bare URL for an attachment
- Display attachment resolution size
- How to check if there is image title, caption, description?
- Custom Gallery HTML only working when images are attached to post/page
- Display random gallery images and its parent post title leading to parent post permalink
- Where does the gallery shortcode gets its attachments from?
- Exclude images from “inserted into post” when trying to get attachments
- How to remove attachments size attribute [duplicate]
- attachment.php code or tutorial
- How to redirect ‘file url’ to ‘post url’ i.e. in attachment.php
- Customizing the attachement page to show rest of all images in a gallery from post
- Check what attached image size is used
- How do I get all attachments that are used in the current post, not just the children?
- Clean up images, delete unused image sizes attached to a post type
- Get title of post image is attached to
- One picture belonging different galleries?
- Correct attachment size
- Post Gallery list attachments except the one used as post thumbnail
- hide attached images of a post
- Get image attachment to a post outside the loop?
- How do I intercept and modify the functionality of wp_get_attachment_image()?
- Unable to get wp_get_attachment_url to show
- Get Attachment Image Class by attachment id
- WordPress Gallery Permalink Structure Displaying Incorrectly
- Use full size images in a specific gallery
- How to get the next and previous image title from attachment or gallery?
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- How do I get just the title from wp_get_attachment_image
- Can i have 2 separate Galleries on 2 separate pages each go to a DIFFERENT Attachment.php file?
- Get an image from the media library. Struggling with the code?
- Programmatically Altering Gallery Link and image size?
- How is it possible that a gallery doesn’t have attachment ids?
- How to view exact image dimensions of a media in Admin view?
- Filter not applied to all image sizes
- wp_get_attachment_image_src calling wrong location
- Get attachment URL from attachment Link in WordPress
- Display setting ‘size’ not available in image settings modal
- Hide Image Container if No Image Attachments
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- attachment.php & flexslider—linking thumbnail to specific image
- Incomplete attachment page
- How to retrieve “custom url” from image attachment in wordpress
- Retreive tags from attached post for media on page
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- wp_get_attachment_link() add rel attribute if the link points to direct image
- ID of images from gallery
- How to save media-form on custom tab
- get_image_tag filter not working
- Gallery Thumbnail Layout Template
- Change attachment inside the_content using filters
- Image Attachments Query Not Working If Post Is Loaded Via Ajax
- Get attachment ID of author_meta image – Attachment Metadata
- How to allow specific extensions and file size to wp_mail attachment?
- attachments with tags and get_posts
- Best way to programatically add “rel” attributes to page and post images
- How to add multiple checkbox elements to media attachments?
- Get attachment next and previous by author only
- media_sideload_image with rewritten urls?
- WooCommerce-like featured gallery
- Gallery Image Numbers?
- Implementing a modal(lightbox) for all images in all post-gallery posts
- Get “Image CSS Class” value from the Advanced Options section
- Display custom gallery in each wordpress post
- Add anchor tag on previous_image_link / next_image_link
- Post images not displaying as attachments
- Paginate Gallery [closed]