Hello.
I used your instructions from the following ticket, in order to display the file name of uploaded pdf files:
https://toolset.com/forums/topic/display-the-file-name-of-uploaded-pdf-files-and-the-link-in-a-different-tab/
Everything works great but I get a notice, one for each of my displayed posts:
Notice: Undefined index: file_url in /wp-content/themes/Divi-Child/functions.php on line 22
Line 22 is this: $url = "{$atts['file_url']}";
The full code I use is this:
add_shortcode( 'my_file_name', 'wpml_hard_link'); // Actually activate the shortcode
function wpml_hard_link($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 = ''; // 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
}
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];
}
Any ideas on hoe to get rid of this notice?
Thank you in advance