hi,
excuse me but I can't understand how to show the file name in my php template.
My script is:
$attachment = types_render_field ("attachments", array ("separator" => ",", "title" => "Download attachment"));
I would like to replace "Download attachment"
with the name of the uploaded file
thanks
Hi Minesh,
I'm sorry but I don't understand how to set it.
I added the shortcode to functions.
In my single page I set the shortcode like this:
<? php echo do_shortcode ('[my_file_name types_field = "course_connected"]')?>
where "corso_allegati" is a "file" repeater.
Looks almost Ok to me how you added the shortcode.
Can you please share file path where you added above code and access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
add_shortcode( 'my_file_name', 'func_print_file_name'); // Actually activate the shortcode
function func_print_file_name($atts) {
$url = "{$atts['file_url']}";
$types = "wpcf-{$atts['types_field']}";
$post_id = $atts['post_id'];
if (!empty($types)) { // if the types_field argument was provided
$urls = get_post_meta($post_id,$types,false); // 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
$arr = explode('/',$fileurl); // Split it up so that we can just grab the end part, the filename
$content .= '<a href="'.$fileurl.'">'.end($arr).'</a><br />'; // 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 '<a href="'.$url.'">'.end($arr).'</a>'; // And return the resultant link
} // We're done!
}