Hello,
In custom fields of posts, i enter a reccuring field with "file attachments" to each post.
A sample post you can see is here hidden link
My question is, instead of showing the full path of the file, is it possible to just present the filename or the file description ?
Thank you
Hi Yannis,
Thank you for contacting us and I'd be happy to assist.
To extract the file name, from the file type custom field, you'll need a custom shortcode:
add_shortcode( 'get_file_name_custom', 'get_file_name_custom_func');
function get_file_name_custom_func($atts) {
$a = shortcode_atts( array(
'url' => ''
), $atts );
$url_arr = explode('/',$a['url']);
return end($url_arr);
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
After that, you'll be able to show only the file names from the repeating file type custom field, like this:
[wpv-for-each field="wpcf-file-field-slug"]
[get_file_name_custom url="[types field='file-field-slug' output='raw'][/types]"]<br>
[/wpv-for-each]
Note: please replace "file-field-slug" with the actual slug of your file type field.
Related documentation links:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
https://toolset.com/documentation/customizing-sites-using-php/functions/#file
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
I implemented the function in the function.php and i tried to enter the code in the content template, but the files are not links.
Can i make them linkable to the actual files ?
Yes, to convert the file names to the links to the actual files, you can use the shortcodes like this:
( ref: hidden link )
[wpv-for-each field="wpcf-file-field-slug"]
<a href="[types field='file-field-slug' output='raw'][/types]" target="_blank">[get_file_name_custom url="[types field='file-field-slug' output='raw'][/types]"]</a><br>
[/wpv-for-each]
The issue is solved in a great way !!!
Thank you so much.
Hello again.
Huge error...
In the files list you can see in hidden link
The links are not FROM the attached files (from each file).
They are the link of the post !!!!
I made a mistake in typing...
My issue is resolved now. Thank you!