Skip Navigation

[Resolved] How to use repetitive field for file upload

This support ticket is created 3 years, 5 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Shane 3 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2310369
Screen Shot 2022-03-07 at 8.28.03 AM.png

I want to add file uploads to my site, when I do it is the complete url I just want it to show the title of the file name how can I get this to work?
This page has a file hidden link down towards the bottom, I want it to be title.pdf or title .file format not the complete url.

#2310555

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Thank you for getting in touch.

Unfortunately this is not something that can be achieved natively with our shortcode as it will display the file url that is stored in the field.

To display only the file name you will need to use some form of custom code to do this. I was able to find on our forums a customer who had a similar issue and they shared their solution.
https://toolset.com/forums/topic/displaying-file-title-with-a-link-for-custom-field-for-manuals-etc/#post-1667641

Please follow the instructions in the link above and let me know if it was able to assist you.

Thanks,
Shane

#2310841

I tried that link you sent and put the function in the toolset custom code but when I try to use the custom short code nothing happens except it shows the custom short code on the front end. I want to get the upload-file name that is the slug from the properties type that I created.

#2311321

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Have you clicked on the Activate button on the custom shortcode editor?

If the activate link hasn't been clicked then the shortcode won't work on the frontend.

Thanks,
Shane

#2311333

Yes It is active and I test ran it everything was good, but the shortcode doesn't work so I am missing something

#2311559

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.

Thanks,
Shane

#2311619

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

It seems the issue is that the shortcodes are not rendering when added to the custom code section in Toolset.

Either way adding it to the functions.php file causes it to work. However I did craft a simpler solution to essentially just trim the URL for the filename only.

// Add Shortcode
function trim_urlbasename( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'url' => '',
		),
		$atts
	);

	return basename($atts['url']).PHP_EOL;

}
add_shortcode( 'trim_urlbasename', 'trim_urlbasename' );

Now to use this all you have to do is craft your solution with the repeating fields shortcode.

<ol>[wpv-for-each field="my-field"]

<li><a href="[types field='my-field' output='raw']> [trim_urlbasename url="[types field='my-field' output='raw']"]</a></li>

[/wpv-for-each]</ol>


Please let me know if this helps. Of course you will replace my-field with the actual slug of your repeating field.
Thanks,
Shane