Use this code if you’re in the loop:
$attachments = get_children( array( 'post_parent' => $post->ID ) );
$count = count( $attachments );
If you’re not in the loop, substitute $post->ID
with the ID of the specific post. But that should count all attachments.
Related Posts:
- How to manage attachment relationships for specific posts in WP 3.5+
- How to trigger a refresh in the media modal
- How can I bulk delete media and attachments using WP-CLI?
- Expanding new Media Uploader in WordPress 3.5
- Uploading Multiple Attachments From Front-End With A Description
- Get all posts (of any post type) an attachment is used in
- How to single click to download image in single post
- Unattaching unlinked images
- Delete attachments from Front end
- Get attachments (get_posts) and WP 3.5 new uploader
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- How to retrieve alt attribute for an attachment (uploaded image)?
- Get the path of the first attached media (single.php)
- Show attached media image if no thumbnail image detected
- media ‘path’ issue / concern when bringing files live
- Media library quick/inline edit
- How to compress image before inserting to wordpress using wp_insert_attachment function?
- Massive photogallery import
- the_time() returning wrong date/time (way in the future)
- Gutenberg Block: Image resolution
- Media Library Mess After FTP … /uploads
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Setting an image as post header (not featured image)
- Using the GetMediaLibrary() method in python-wordpress-xmlrpc.media, how to iterate over the result?
- Remove attached media
- How To Retrieve An Image Attachment’s Alt Text?
- How to Fix HTTP Error When Uploading Images?
- Can I add a Category Metabox to attachment?
- Change attachment filename
- How to get attachment file name not attachment URL
- How to use taxonomies on attachments with the new Media Library?
- 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
- Getting a taxonomy’s thumbnail url
- Stop WordPress from reserving slugs for media items?
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- Changing attachment urls?
- Can I use the wp media uploader for my own plugin?
- Add custom class to attachment in media library grid mode
- Open media frame and select an attachment
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- media_handle_upload for local files?
- How can I UN-attach media from a post?
- Put the media uploader in a metabox
- Validate alt text for attachments?
- get_attached_media() returns empty array if media file already used by another post
- 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 do I detach images from posts?
- 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?
- How to get all files inserted (but not attached) to a post
- Custom function to rearrange attachments when creating posts – Almost there
- Detect if is image unattached
- Password protect some uploaded files, so only logged-in users can view them
- Replacing all attachment links in post with media file link
- delete attachment from front end
- 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
- How to add media from front-end to an existing post?
- Disable slow media queries?
- How to set author for post AND post attachments
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Retrieving a custom link on an attachment
- Get attachment from post
- How can I display custom fields value from attachment media?
- Add column for attachment file size
- Creating a multi-file upload form on the front end for attachments
- how to test for attached image
- How do i upload an image and return the image id?
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Gel all image from certain post type
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link
- Change the Permalink for wordpress attachment
- How to upload image from front end and save in media library?
- Can i hide the attachments from media which I uploaded from front end?
- ID of images from gallery
- Get the attachment URL on single.php
- How to get list of paths (not urls) for an image
- wp_get_attachment_image_src always returns false
- Exact image sizes
- Upload images and attachments from frontend form