Jaboli here is an another solution.
First I have created a function that detects if post has shortcode anywhere in the content.
`function price_id($tempCheck){
$tempContent = get_the_content();
$tempVerify = strpos($tempContent,$tempCheck);
$pattern = ‘@purchase_link id=”(.*?)”@si’;
preg_match_all($pattern,$tempContent,$matches);
if(!$tempVerify === false) {
$idnum = $matches[1][0];
return $idnum;
}
}`
I 95% attach just one file to my posts. you might need to tweak the function so it runs all the array vars.
So this function gives us the id of the download file.
after that i just use this code within the post loop:
<?php echo edd_get_download_sales_stats(price_id("purchase_link id="));?>
and it gives me the number of downloads for that file.