How do I count the number of media attachments a specific post has?
Output example: This post has 22 photos.
Use this code if you're in the loop:
If you're not in the loop, substitute
My take would be this:
There is no need to query for all post fields if only intent is to count amount.
Also note that attachment is not necessarily image and that is not easy (possible?) to query for, see