- This topic has 8 replies, 2 voices, and was last updated 4 years, 2 months ago by
Trisquelmedia SL.
hi!
I have a little code
$download_count = get_package_data(6730,'download_count');
6730 ► is the ID of the package
I would like instead of custom id, i would like was current package ID
How i do that?
Thxs
Hello Trisquelmedia SL,
Hope you are well. Can you please elaborate more on your query? you can share some code snippet screenshots or the details code structure too for getting the issue in a close look. please let me know
Thank you and regards
Sure:
I have created a shortcode [DownloadCounter] it returns download count of a package (in this case package ID “6730”)
function shortcode_download() {
$download_count = get_package_data(6730,'download_count');
return $download_count;
}
add_shortcode('DownloadCounter', 'shortcode_download');
I dont want to put manually package ID (6730), instead I would like it to (2 different things) :
1) Modify the function to automatically get package ID from the package shown on the current page.
2) Create another function to return the total downloads of the sum of all packages.
Regards
Hello Trisquelmedia SL,
You can try this code,
function shortcode_download($attributes) {
$package_id = intval( $attributes['id'] );
$download_count = get_package_data($package_id,'download_count');
return $download_count;
}
add_shortcode('DownloadCounter', 'shortcode_download');
So, the shortcode will be [DownloadCounter id='packageid' ]
please check and let me know
Thank you and regards
Thxs Nayeem!
Anywhere to modify that code to show the total downloads (summatory all packages individual created downloads)
Hi Trisquelmedia SL,
For total downloads of the sum of all packages, you can use this the below code,
<?php _e( "Total Downloads" , "download-manager" ); ?>
<?php echo $wpdb->get_var("select sum(meta_value) from {$wpdb->prefix}postmeta where meta_key='__wpdm_download_count'"); ?>
And for a certain user, please use this code snippet in your theme functions.php
add_shortcode('UserTotal', 'TotalUserDownload');
function TotalUserDownload() {
global $wpdb, $current_user;
$var = "Total Downloads: ";
$var .= number_format($wpdb->get_var("select count(*) from {$wpdb->prefix}ahm_download_stats where uid = '{$current_user->ID}'"),0,'.',',');
return $var;
}
Use the shortcode [UserTotal]
I hope it will work fine for you now
Thank you and regards
Thxs Nayeem!!!
Regards
Glad to hear that your issue has been resolved. If you get some free moments, please give us a 5* here and add your valuable review about our plugin, it will inspire us a lot.
Thank you and Regards
Sure!
Thxs
The topic "Current $id in a download manager function" is closed to new replies.