How to Add Uploaded Media to WP-DownloadManager
To connect the “file” value to the “file_id” value, I just add the following function to the bottom of the wp-downloadmanager.php file:
function get_download_id($content) {
global $wpdb;
// Get ID numbers from the value in the "file" column
$content = $wpdb->get_var("SELECT file_id FROM $wpdb->downloads WHERE file ='$content'");
return $content;
}
Then I will pull this variable into each page or template where I want to track downloads. In my case, I add it to the top of the forms.php file:
$downloadID = get_download_id($FileName);
Where I’ve pulled my file name into a variable called $FileName.
Then I stick the $downloadID variable on the end of the download url and I have tracking for all of my downloads.
That said, I’m aware that you probably don’t have a custom field for all of your file names. If you uploaded via the Media Library, you are in luck. The “file” field in the wp_downloads table matches the “post_title” value in the “wp_posts” table for your attachments uploaded through the media library. So you can match those up the same way that I do in this example, but you’ll have to pull in your “post_title” of the attachment and stick it into a variable first. This will vary depending on your template, theme, etc.





Thank for Information
Hi, cool post. I have been wondering about this topic,so thanks for writing.
Thanks for your valuable information. I will try it……
Thank you for this post. This is what I’m looking for.