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 get attachment file name not attachment URL
- How to cleanly delete attachment but retain original file?
- Validate alt text for attachments?
- Replacing all attachment links in post with media file link
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- How can I display custom fields value from attachment media?
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Add_Filter example for wp_get_attachment_link
- Can i hide the attachments from media which I uploaded from front end?
- attachment url rewrite
- Automatically delete attachments and posts [closed]
- How to delete orphan attachments?
- Add a header before fields added with the attachment_fields_to_edit() filter
- Get the title and URL of the attachment parent post
- Confused with attachment mimetype order
- query attachment images … if no attachments -> get attachments of parent page?
- Replacing with(out) regex link to attachment by links to files
- Getting attachment images is cloning some of them
- rename attachments based on parent-post-title on upload
- Rename attachments during upload no matter what filetype
- Link all WordPress images size
- Contact Form 7 Data As Attachment [closed]
- Displaying Post Attachment(s) at Top of single.php
- Detach an image from a page using php
- Images not being generated at correct size
- Image still attached to post even after removing it as featured image
- custom admin thumbnail for videos, not getting post’s id?
- Custom Gallery HTML only working when images are attached to post/page
- Image Gallery Numbers for 3.5
- How do I link an image to the post it is attached to?
- How to delete a custom file from upload directory when deleting its post
- Query to only return the 2 newest post attachments (images)?
- Getting “too many redirects” when using wp_redirect for attachment page
- Clean up images, delete unused image sizes attached to a post type
- What is the best way to store thumbnails for a non-image attachment?
- What will happen if I delete all my attachment type posts from database?
- filter get_children to return all mime types EXCEPT ‘x’
- Weird string offset errors when displaying post attachments
- Add audio attachment link to RSS
- Links to my uploads went crazy
- How does WordPress decides how many sizes of an image to create?
- hide attached images of a post
- How to add a caption to an image attachment in a file list?
- Change categories count to include media attachments
- Undoing define( ‘UPLOADS’, ”.’files’ ); to repoint to “wp-content/uploads” folder
- Upload image and assign it’s id to post
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- Insert attachments from custom uploader into post (regular uploader style)
- Can’t sort get_posts by post_mime_type
- How can I rewrite old attachment URLs?
- How to list “invisible” Auto Drafts?
- How to add media from front-end to an existing post and edit file title
- How is it possible that a gallery doesn’t have attachment ids?
- How to restrict add media library only to images of the same post family?
- Media item permalink goes to source file instead of attachment.php
- Attachment metadata has value of ‘1’
- Display audio file in audio.php
- Display setting ‘size’ not available in image settings modal
- Attachment file display link text
- Limit attachment caption characters
- Get video attachment ID and display length
- missing attachment are showing as 404
- controlling whether upload is attached to post or not
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- Add link to attachment for old posts
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- Drupal 6 to WordPress migration – media attachments
- Retreive tags from attached post for media on page
- Move caption in on attachment page
- Change attachment inside the_content using filters
- Bulk delete media by year
- Media library upload hook
- How to properly move media files and update data?