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.

pages: 1 2 3 4 5 6 7

4 Responses to How to Add Uploaded Media to WP-DownloadManager

  1. LikeCamping says:

    Thank for Information

  2. KrisBelucci says:

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

  3. Ismail says:

    Thanks for your valuable information. I will try it……

  4. Abnehmen says:

    Thank you for this post. This is what I’m looking for.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">