I have a form which accepts multiple file links.
hidden link
Yet it only generates a single link in the content output.
hidden link
And it appears to concatenate the URLs into a single link, which of course produces a 404 error.
hidden link
Yet it only generates a single link in the content output.
Hello, can you describe how you are including this custom field in your template or post contents?
- Typically the best option for displaying a field that allows multiple values is the Repeating Field block (screenshot attached here).
- If you are using a different block in the Block Editor, please explain which block, and if possible provide some screenshots so I can see the block configurations.
- If you are using a shortcode or a series of shortcodes, please copy + paste those here for me to review, and tell me where you have placed these shortcodes.
- If you are using custom PHP, please copy + paste that code here fo me to review.
Thanks for the feedback.
I'm using Beaver Builder with Beaver Themer.
Themer has the ability to insert ToolSet Custom fields into a page from their Text Editor module.
hidden link
As you can see from this screenshot I have enabled the field as "repeatable".
hidden link
Okay I see, unfortunately we don't really have any control over how Beaver Themer/Beaver Builder renders Toolset fields. The code that determines how the fields are rendered is managed in their plugins, and Toolset does not really influence how their software implements data from Types fields. I suggest reaching out to their support team to let them know this feature is not working as expected with repeating file fields, so they can correct the behavior in their software.
Until they can address the problem, have you tried using a Types field shortcode instead? You can try inserting this shortcode in the Text Editor instead of using the Beaver Themer feature to insert a field:
[types field="article-pdf" separator=" "][/types]
That should output the repeated file links, each one separated by a space.
"Until they can address the problem, have you tried using a Types field shortcode instead?"
Is there a way to wrap these raw links individually in other HTML e.g., using them as the href attributes of one or more anchor tags?
Is there a way to wrap these raw links individually in other HTML e.g., using them as the href attributes of one or more anchor tags?
If you mean you want to customize the HTML that wraps each link, yes, there are different approaches that allow for different types of customization. You can use the wpv-for-each shortcode to apply a custom HTML markup template to all instances of the field in a loop. Customizing the template to be unique for each instance is not really intuitive in this approach.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-for-each
Notice the field slugs and the use of the wpcf- prefix in the following example:
[wpv-for-each field="wpcf-article-pdf"]
<a href="[types field='article-pdf' output='raw'][/types]">Download [types field='article-pdf' output='raw'][/types]</a>
[/wpv-for-each]
The wpcf- prefix is required in the wpv-for-each field attribute, but should not be used in the loop template. Notice that the template is not really easily adjustable for individual instances, beyond the field value itself.
Another option is you can use the Types field shortcode and access individual instances directly by instance index number. This gives you more flexibility in terms of customizing the template for each instance, but isn't integrated with any kind of looping mechanism.
https://toolset.com/documentation/customizing-sites-using-php/functions/#file (click the orange +More link)
Example:
<a href="[types field='article-pdf' index='0' output='raw'][/types]">Download the first file</a> |
<a href="[types field='article-pdf' index='1' output='raw'][/types]">Download the second file</a> |
<a href="[types field='article-pdf' index='2' output='raw'][/types]">Download the third file</a>
Since there is no looping structure to repeat a template, you might end up with extra links or too few links depending on the number of field instances.
For the most flexibility, create a custom shortcode using PHP and build your links by looping over the values from get_post_meta, something like:
$html = '';
$files = get_post_meta( 12345, 'wpcf-article-pdf', false);
$index = 1;
foreach($files as $file) {
$html .= '<a href="' . $file . '">Download file #' . $index . '</a>';
$index++;
}
return $html;
https://codex.wordpress.org/Shortcode_API