Current $id in a download manager function

in Download Manager Free

Viewing 9 posts - 1 through 9 (of 9 total)
Nov 26, 2021 at 8:43 am
#165025
Participant
Trisquelmedia SL
OP

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

Nov 26, 2021 at 9:19 am
#165029
Moderator
Nayeem Riddhi
Staff

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

Nov 26, 2021 at 9:33 am
#165030
Participant
Trisquelmedia SL
OP

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

Nov 27, 2021 at 5:09 am
#165052
Moderator
Nayeem Riddhi
Staff

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

Nov 27, 2021 at 10:57 am
#165057
Participant
Trisquelmedia SL
OP

Thxs Nayeem!

Anywhere to modify that code to show the total downloads (summatory all packages individual created downloads)

Nov 27, 2021 at 1:57 pm
#165059
Moderator
Nayeem Riddhi
Staff

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

Nov 29, 2021 at 8:34 am
#165086
Participant
Trisquelmedia SL
OP

Thxs Nayeem!!!

Regards

Nov 29, 2021 at 11:44 am
#165087
Moderator
Nayeem Riddhi
Staff

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

Nov 29, 2021 at 11:49 am
#165088
Participant
Trisquelmedia SL
OP

Sure!

Thxs

Viewing 9 posts - 1 through 9 (of 9 total)

The topic "Current $id in a download manager function" is closed to new replies.