This short post will show toy how to find out how many attachments there are in the Media area programmatically.
You will need to use wp_count_attachments() which returns an object which contains different properties.
Each property corresponds to a MIME type. In the code below we only care about the total number of attached files so that's why we're adding them them up.

[code]
$count = 0;
$counts_obj = wp_count_attachments();
$counts_array = (array) $counts_obj;

foreach ($counts_array as $mime_type => $cnt) {
    $count += $cnt;
}
[/code]

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer