I’m guessing you’ll need to fetch the post content and parse it using something like this as a guide (pasted code from above link for future reference).
// Get the all post content in a variable
$posttext = $post->post_content;
$posttext1 = $post->post_content;
// search for the src="" in the post content
$regular_expression = '~src="[^"]*"~';
$regular_expression1 = '~<img [^\>]*\ />~';
// grab all the images from the post in an array $allpics using preg_match_all
preg_match_all( $regular_expression, $posttext, $allpics );
// Count the number of images found.
$NumberOfPics = count($allpics[0]);
// This time we replace/remove the images from the content
$only_post_text = preg_replace( $regular_expression1, '' , $posttext1);
// Check to see if we have at least one image
if ( $NumberOfPics > 0 )
{
/* profit */
}
Related Posts:
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- How can I bulk delete media and attachments using WP-CLI?
- complex restriction of items in media library
- Edit image / Delete image link
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Unattaching unlinked images
- Show Post ID in “Find Posts or Pages” box in Media Library?
- Gel all image from certain post type
- Can i hide the attachments from media which I uploaded from front end?
- Get the attachment URL on single.php
- Perform a custom (bulk) action in media view
- How to retrieve alt attribute for an attachment (uploaded image)?
- Where does the gallery shortcode gets its attachments from?
- Control attachments menu order with jQuery Sortable
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Get an image from the media library. Struggling with the code?
- Media Library Mess After FTP … /uploads
- Media item permalink goes to source file instead of attachment.php
- wp_get_attachment_image_src calling wrong location
- Removing images deleted from uploads folder, from Media Library
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- Is there a way to add Reattach and Unattach links in image gallery?
- How to save media-form on custom tab
- Bulk delete media by year
- Media library upload hook
- How to manage attachment relationships for specific posts in WP 3.5+
- Programmatically adding images to media library
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- custom fields for attachments?
- Get attachment from post
- Add column for attachment file size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- ID of images from gallery
- wp_get_attachment_image_src always returns false
- Adding attachment file name to email link
- How to allow specific extensions and file size to wp_mail attachment?
- How to grab the first two image attachments from a post?
- wp_insert_post featured image from library
- Get attachments by user
- Get url from file uploaded in Media Library
- attachments with tags and get_posts
- Hide “Gallery Settings” and “Insert into Post” button from Attachment window
- How can I change wordpress attachment url and protect it?
- Adding class to next/prev image link in attachment.php
- Getting ID from ajax response of async-upload.php
- How to add multiple checkbox elements to media attachments?
- Get attachment next and previous by author only
- Edit default image attachment size
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Strip the folder path away from wp_get_attachment_url to show filename only
- Need to get array of images ID attached to post
- How to fetch only media that was already attached to a post/page?
- How to set a conditional statement for $attachment->post_excerpt, to check for value?
- wp_mail not sending attachment
- How to check if there is image title, caption, description?
- Display random gallery images and its parent post title leading to parent post permalink
- Don’t show attachments if they are inserted in post
- How to remove attachments size attribute [duplicate]
- How do I get all attachments that are used in the current post, not just the children?
- Is there a move_attachment_file() function in wordpress?
- Auto create file and send it via wp_mail()
- Create page from post attachments
- Attach pdf from dynamic url
- Is there a function for getting the post/page that an attachment is related to?
- Automatically deactivate link for attachments
- How to set order for attachment form field?
- Display a post attachment depending on the caption
- Getting attachment post using wp_get_attachment_link
- File Attachment display title in template
- add image caption
- wp_mail Allow Remote Attachments from CDN
- Get all post embedded images
- Filter not applied to all image sizes
- Zip a file and add as attachment
- Remove post with attachments hook
- Setting an image as post header (not featured image)
- Using the GetMediaLibrary() method in python-wordpress-xmlrpc.media, how to iterate over the result?
- How to restrict users to only access their own media files in wordpress
- wp_mail doen’t send mails whit attachment
- How to link images to attachment.php [duplicate]
- Check whether attachment ID is associated with more than one post?
- How to remove attachments from main query via pre_get_posts?
- Post attachments doesn’t show after manual db import
- How to get boolean if file A is attached to post B
- Showing the attachment for a page?
- How can we select attachements based on Caption?
- Gallery Thumbnail Layout Template
- Custom Fields, Media uploader, Attachments
- Change the next thumbnail to text