Written by Admin on 2025-05-06
How to Get Filename by ID in WordPress Download Manager
WordPress Download Manager (WDM) is a powerful tool used to manage and sell digital downloads directly from your WordPress website. It offers various features like download tracking, restrictions, and customer management. However, there might be times when you need to retrieve the filename of a specific download ID. In this article, we'll learn how to get the filename by ID in the WordPress Download Manager.
Retrieve Filename by ID
To retrieve the filename of a specific download ID, we can make use of the WDM function get_package_info()
. This function returns an array of information about the specified package, including the name of the file. To implement this function, follow the steps below:
- Open your WordPress website's functions.php file and add the following lines of code:
function get_package_name_by_id($id) {
$package = WdmPackage::get_instance()->get_package_info($id);
return $package['filename'];
}
Save the file and exit.
Call the function wherever you want to retrieve the filename for a specific download ID. Specify the ID as a parameter, as shown below:
$filename = get_package_name_by_id(123); //replace 123 with your preferred download ID
- You can now use the
$filename
variable as needed.
Conclusion
The WordPress Download Manager is a great tool that simplifies the management and sales of digital downloads on your website. Retrieving the filename for a particular download ID is an essential feature, especially if you need to display or manipulate information about the file. With the get_package_info()
function, you can quickly and easily retrieve the filename by ID and use it as you wish. Try it out, and let us know in the comments if you have any further questions or suggestions!