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.

Related posts:

  1. Search and Replace a Custom Field in WordPress using PHPMyAdmin
  2. Search and Replace MySQL using PHPMyAdmin
  3. How to Bulk Import into a MySQL Database
  4. Delete Comment Spam using a Cron Job
  5. Allowing Uploads via the Media Uploader

Comments

2 Responses to “How to Add Uploaded Media to WP-DownloadManager”

  1. LikeCamping on May 22nd, 2009 9:05 am

    Thank for Information

  2. KrisBelucci on June 1st, 2009 9:45 pm

    Hi, cool post. I have been wondering about this topic,so thanks for writing.