I used the code from this post (https://toolset.com/forums/topic/display-the-file-name-of-uploaded-pdf-files-and-the-link-in-a-different-tab/). It works great except if there is no are file uploads, it displays the title of the post linked. It'd be great if didn't display anything in the case there were no file uploads.
Here is the final code I used:
'add_shortcode( 'attached_files', 'attached_files_function'); // Actually activate the shortcode
function attached_files_function($atts) {
global $post; // So we can get the post meta later on
$url = "{$atts['file_url']}";
$types = "wpcf-{$atts['types_field']}";
if ($types) { // if the types_field argument was provided
$urls = get_post_meta($post->ID,$types); // let's get the (potentially multiple) values
$content = '<h2>Project Files</h2><ul class="last-of-type">'; // Setting up a variable to hold the links so we can return it later
foreach ($urls as $fileurl) { // Let's iterate for each of the multiple values
$filetitle = get_the_title(pippin_get_image_id($fileurl));
//$arr = explode('/',$fileurl); // Split it up so that we can just grab the end part, the filename
$content .= '
'.$filetitle.'
'; // Create the link and store it in the $content variable
}
$content .= '';
return $content; // Return the content as the shortcode value
} else { // Else we didn't use the fields_type argument, we just needed one URL we provided explicitly
$arr = explode('/',$url); // So let's split that URL up so we can grab the end
return '
'.end($arr).'
'; // And return the resultant link
} // We're done!
}
// retrieves the attachment ID from the file URL
function pippin_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}'
Thank you for your time!