Skip Navigation

[Resolved] File Field Group – display show uploaded file title

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

Problem:
File Field - display uploaded file title

Solution:
There is no native way to display the uploaded fiel/pdf title but there is workaround that you can use by adding custom shortcode.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/file-field-group/#post-1369789

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
=> https://toolset.com/documentation/user-guides/repeating-fields/#Displaying%20Repeating%20Fields

This support ticket is created 5 years, 3 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
- 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 4 replies, has 2 voices.

Last updated by craigH-5 5 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1369427
Screen-Shot-2019-10-24-at-4.44.08-PM.jpg

Tell us what you are trying to do? Creating links to download PDF product literature. I want the PDF Title name to display, not the link url.

Is there any documentation that you are following? No

Is there a similar example that we can see? Yes

What is the link to your site? hidden link

#1369789

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

There is no native way to display the uploaded fiel/pdf title but there is workaround.

Please try to add the following code to your current theme's functions.php file
or
"Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_shortcode( 'display_file', 'func_display_file_info');
function func_display_file_info($atts) {
global $wpdb;

$atts = shortcode_atts( array(
 'url' => '',
'info' => '', // title, alt or id return
), $atts);

$res = '';
$url = $atts['url'];
$attachment_id = $wpdb->get_var($wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE guid = %s", $url
));

if($atts['info'] == 'title'){
 return  get_the_title($attachment_id);
}

if($atts['info'] == 'alt'){
return  get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
}

if($atts['info'] == 'id'){
return $attachment_id;
}

}

Once you added the above code, you can add the following code to your content teplate or view where you are currently displaying your PDF links.

[wpv-for-each field="wpcf-YOUR-FIELD-SLUG"]
<a href='[types field="YOUR-FIELD-SLUG"  raw="true"][/types]' > 
[display_file info="title" url="[types field='YOUR-FIELD-SLUG' raw='true'][/types]"]
</a>
[/wpv-for-each]

Where:
- Replace YOUR-FIELD-SLUG with your original field slug

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
=> https://toolset.com/documentation/user-guides/repeating-fields/#Displaying%20Repeating%20Fields

#1370017

This worked perfectly. Now I'm trying to add separator='<br> ' or unordered list because there are multiple download links that need to be on seperate lines for organization. I've tried to insert this in a couple places, but I can't get it to work.

#1370079

Minesh
Supporter

Languages: English (English )

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

Well - you should add the separator to your wpv-for-each loop.

For example:

[wpv-for-each field="wpcf-YOUR-FIELD-SLUG"]
<a href='[types field="YOUR-FIELD-SLUG"  raw="true"][/types]' > 
[display_file info="title" url="[types field='YOUR-FIELD-SLUG' raw='true'][/types]"]  <br />
</a>
[/wpv-for-each]
#1370099

Got it. I was adding separator='<br> '

Thank you!