This function returns the values of the package info with the specified key from the specified package.

<?php get_package_data($id, $key); ?>



$id: The ID of a package

$key: A string containing the name of the package info you want.

Valid Keys:

  • access
  • download_count
  • view_count
  • version
  • link_label
  • quota
  • download_limit_per_user
  • package_size
  • package_size_b
  • individual_file_download
  • template
  • page_template
  • password_lock
  • password
  • password_usage_limit
  • email_lock
  • tweet_lock
  • facebook_lock
  • googleplus_lock
  • files
  • fileinfo
  • package_dir
  • publish_date
  • expire_date
  • icon
  • base_price
  • sales_price
  • variation



To get the download_count for a package with ID 2:

$download_count = get_package_data(2, 'download_count');
echo $download_count;


Last Updated: Nov 16, 2014


  • brunzino

    I’m trying to get a package’s full path (e.g. /var/www/wordpress/wp-content/uploads/my_file.pdf) for a given package.

    $path = get_package_data($id, 'package_dir');     // returns nothing. 
    $info = get_package_data($id, 'fileinfo');     // also returns nothing. 
    $count = get_package_data($id, 'download_count');     // returns an integer. 

    Is this a bug? Is there a better way to get the absolute path of a package?

    • Shahriar

      package_dir and fileinfo are returning null probably because there is no dir and file attached with that package. However if you only attach package dir, then get_package_data($id, 'package_dir'); will return the attached dir path, but still fileinfo var will return null as fileinfo only stores custom file info, like custom file title and file password.

      However, they are actually post meta with prefix __wpdm_ and you can directly read them using get_post_meta function too, int that case you need to add the prefix before variable name, like $path = get_post_meta($id, '__wpdm_package_dir', true);


    Hi there,

    Is it possible to pass the user id into the get_package_data? Im needing to display if a item has been downloaded or not by the current user. I can you have ‘download_count’ but that seems to be an overall amount of download clicks across all users?


    • Shaon

      You can use following code to find if a user downloaded the items or not.

      function is_user_downloaded($pid, $uid){
          global $wpdb;
          $uid = (int)$uid;
          $pid = (int)$pid;
          $ret = $wpdb->get_var("select uid from {$wpdb->prefix}ahm_download_stats where uid='$uid' and pid = '$pid'");
          if($ret && $ret == $uid) return true;
          return false;

        Hi Shaon,

        Thanks for the reply. I cant seem to get this to work for me though. Its assigned the user id and post id fine, but the $ret value is outputting as NULL each time, so the if statement isnt doing anything. Any ideas why?


  • Kevin Fairburn

    Sorry to be a bit thick, but I need to show the size of each individual file in the package download table. what do I need to put in the template please?

    • Shahriar

      No ready function is available for that. But you can user following code to get individual file sizes:

      $files = \WPDM\Package::getFiles($ID);
      $filesizes = array();
      foreach($files as $index = > $file){
            $filesizes[$index] = filesize($file);
  • Kevin Fairburn

    … and unrelated, but where do I set the default package template please for all packages?

Leave a Reply