I have done this lots of times and below is a code snippet that will download all the values for a custom field key. Remember that you can have multiple duplicate entries for the same named custom field key. This is tremendously useful as it is gathered into a php array for processing using the:
get_post_custom_values('enter_field_key', $post->ID);
function. You can see more info about it here:
https://codex.www.ads-software.com/Function_Reference/get_post_custom_values
There are other choices to manipulate the custom field data, this is just one example that I have used over and over again. The advantage to you is that you can use it to handle any number of file downloads per post, you are not just limited to one. ??
Anyway, onto the code:
$file_download_array = get_post_custom_values('enter_field_key', $post->ID);
if(count($file_download_array) >= 1) {
if(count($file_download_array) > 1) { // multiple download files to show
foreach($file_download_array as $file) {
// add code here to handle/show files
}
} else { // single download file to show
// add code here to handle/show file
}
}
Just change the ‘enter_field_key’ with your custom field key, and you are good to go!