Skip Navigation

[Resolved] show name file in types_render_field repeater file

This thread is resolved. Here is a description of the problem and solution.

Problem:
show name file in types_render_field repeater file field

Solution:
You need to add the custom shortcode to get the filename of uploaded file.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/show-name-file-in-types_render_field-repeater-file/#post-1227773

Relevant Documentation:

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by federicoA 5 years ago.

Assisted by: Minesh.

Author
Posts
#1227484

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

#1227631

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to display the name of the uploaded file you need to add custom shortcode.

Please check the following reply by me from one of the related tickets:
=> https://toolset.com/forums/topic/wpv-post-featured-image-output-file-name/#post-335862

#1227686

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.

what am I doing wrong?
thanks federico

#1227687

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#1227740

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - the SFTP access details you shared with me is not working. I'm getting following error message:

Error:	Network error: Connection refused
Error:	Could not connect to server

Do I need to sue any specific port? or something else?

Update: wp-admin access details are also not working.

Can you please send me working (wp-admin and FTP) access details.

I have set the next reply to private which means only you and I have access to it.

#1227743

I'm sorry.
Port: 2205

#1227747

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks SFTP access details now working.

Please share wp-admin working access details as its not working.

I have set the next reply to private which means only you and I have access to it.

#1227773

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code as given under:

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!
      
}

And calling the shortcode as given under:

<?php echo do_shortcode( '[my_file_name types_field="allegati" post_id="'.$id.'"]'); ?>

The issue was the post ID was not found so we are passing the current post id using post_id attribute.

I can see now file name is printed:
=> hidden link

#1227791

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.