Home / Archive / MemberPress: Add a Shortcode To Display the Number of Total Downloads for All Files
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add a Shortcode To Display the Number of Total Downloads for All Files

Adds the following shortcode: [mepr-display-total-downloads]. When added to any page or post, the shortcode will display the total number of downloads across all files imported through the MemberPress Downloads add-on.

Code Preview
php
<?php
add_shortcode( 'mepr-display-total-downloads', function() {
	global $wpdb;
	$downloads_old = $wpdb->get_var( "SELECT SUM(download_count) FROM {$wpdb->prefix}mpdl_file_downloads" );
	$downloads_new = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->prefix}mpdl_file_stats" );
	
	$downloads_old = isset( $downloads_old ) && $downloads_old != null ? $downloads_old : 0;
	$downloads_new = isset( $downloads_new ) && $downloads_new != null ? $downloads_new : 0;
	
	return $downloads_new + $downloads_old;
});

Comments

Add a Comment