function has_image_attachment($post_id) {
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image/jpeg',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post_id
);
$attachments = get_posts($args);
if(is_array($attachments) && count($attachments) > 0) {
//Has image attachments
return true;
} else {
return false;
}
}
Related Posts:
- get_the_post_thumbnail() doesn’t taking style attribute
- Detect if is image unattached
- Retrieving a custom link on an attachment
- Gel all image from certain post type
- ID of images from gallery
- Hide “Gallery Settings” and “Insert into Post” button from Attachment window
- Getting attachment images is cloning some of them
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Reorder “menu order” of attachments to another predefined order
- Add image attachment to post via coding?
- Ordering of gallery images without using shortcode in theme
- 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?
- hide attached images of a post
- WordPress Gallery Permalink Structure Displaying Incorrectly
- How do I get just the title from wp_get_attachment_image
- changing the default picture size link url
- Programmatically Altering Gallery Link and image size?
- How is it possible that a gallery doesn’t have attachment ids?
- ID of images from gallery
- How to save media-form on custom tab
- Get all images from posts with maximum number and without featured image
- Gallery Thumbnail Layout Template
- How To Retrieve An Image Attachment’s Alt Text?
- How to get image title/alt attribute?
- Turn a URL into an Attachment / Post ID
- How to Fix HTTP Error When Uploading Images?
- How to manage attachment relationships for specific posts in WP 3.5+
- Can I add a Category Metabox to attachment?
- Programmatically get images by URL and save in uploads folder
- Get the first image from post content (eg.: hotlinked images)
- Change attachment filename
- How to get attachment file name not attachment URL
- How to trigger a refresh in the media modal
- Delete original image – keep thumbnail?
- Get all post attachments except featured image
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- getting attachement images src and add classes
- How can I bulk delete media and attachments using WP-CLI?
- Set Featured Image Front Frontend Form
- Is it possible to query all posts that don’t have an attachment?
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- How to paginate wordpress [gallery] shortcode?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- How to find attachment by it’s name?
- media_sideload_image generates blank?
- media_handle_upload for local files?
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- Cropped featured image replaces original image in gallery
- complex restriction of items in media library
- Remove duplicate attachments
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Insert an image into a post by API
- How to single click to download image in single post
- delete attachment from front end
- Unattaching unlinked images
- How to get attachments for a specific post type?
- Give attachments an archive page
- custom fields for attachments?
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Show Post ID in “Find Posts or Pages” box in Media Library?
- URL rewrite with add_rewrite_rule and attachment_id
- PHP/Manual use of images? – 2 Questions
- How to add media from front-end to an existing post?
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- How to set author for post AND post attachments
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Get attachment from post
- How can I display custom fields value from attachment media?
- Add an image gallery to a custom post type?
- Delete attachments from Front end
- Programatically creating image attachments from local URLs and setting featured image
- Add column for attachment file size
- Creating a multi-file upload form on the front end for attachments
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Get attachments (get_posts) and WP 3.5 new uploader
- get post attachments of a particular size
- How to remove title attribute from gallery links and images
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link