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
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
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.
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]
Got it. I was adding separator='<br> '
Thank you!