Tell us what you are trying to do?
Hello
So I have a form with repeatable file upload.
When customising the template view loop I'm only able to set a static title for link to the uploaded file. I'm really looking to use a dynamic title based on the uploaded file name. Is there a way to do this please?
Thanks
Hello,
There isn't such kind of built-in feature within Toolset plugins, it is possible with some custom codes, for example, the custom file field is using slug "my-file", you can try these:
1) create a custom shortcode [get_mime_type], put below codes into your theme/functions.php:
add_shortcode('get_mime_type', 'get_mime_type_func');
function get_mime_type_func($atts, $content = ''){
// Attributes
extract( shortcode_atts(
array(
'option' => 'extension',
), $atts )
);
$content = wpv_do_shortcode($content);
$path_parts = pathinfo($content);
$res = '';
if($path_parts[$option]){
$res = $path_parts[$option];
}
return $res;
}
With above shortcode you can get the file name by specifying the shortcode attribute option="basename", for example:
[get_mime_type option="basename"]<em><u>hidden link</u></em>;
Will output result: file1.zip
You can find more options in PHP document:
hidden link
2) Use above shortcode, like this:
<ol>[wpv-for-each field="wpcf-my-file"]
<li><a href="[types field="my-file" output="raw"][/types]" ><span class="[get_mime_type][types field="my-file" output="raw"][/types][/get_mime_type]">[get_mime_type option="basename"][types field="my-file" output="raw"][/types][/get_mime_type]</span></a></li>
[/wpv-for-each]</ol>
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
Iterate through multiple items in a post meta field and output the enclosed text for each item. Including Types repeating fields.
Thanks Luo this is really appreciated!
Added to theme functions and then short code in Fields and Text but it doesn't seem to be working. I wondered if it was because of the same type commas in the short code as with html so tried changing it so only double quotes were used with href and span. It's still not displaying on front end.
<ol>[wpv-for-each field='wpcf-my-file']
[get_mime_type option='basename'][types field='my-file' output='raw'][/types][/get_mime_type]
[/wpv-for-each]</ol>
Please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URL, I need to test and debug it in a live website, thanks
Thank you I got this working now!