Skip Navigation

[Resolved] No shortcode for file name of uploaded Pdf file under multivalue file field

This support ticket is created 7 years, 4 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Noman 7 years, 4 months ago.

Assisted by: Noman.

Author
Posts
#526136
whatiwant.png
now.png
reso.png

I have a multifield file upload field for pdf,
I need to output file title name seen when uploading on media library, instead of the file path when I use the field on content template, tried to look around other support threads, could not get direct help.
What I need is to show file title and link it to pdf path ,
so when I click on file name displayed , it will take me to a path where the pdf will open on browser.

Please help on this!
I am stuck!

Regards!

#526172

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Undule,

Thank you for contacting Toolset Support. We can add a custom shortcode to get the Uploaded file Title and Link.

1. Please add this code in your theme’s functions.php file:

add_shortcode( 'wpv_display_file_name', 'wpv_display_file_title_func');
function wpv_display_file_title_func($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'){
        $res = get_the_title($attachment_id);
    }
    if($atts['info'] == 'alt'){
        $res = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
    }
    if($atts['info'] == 'id'){
        $res = $attachment_id;
    }
    return $res;
}

2. Then you can use the following shortcode in your View or Content template:

<a href="[types field='resources' link='true' separator=', ' output='raw'][/types]" target="_blank" > [wpv_display_file_name info="title" url="[types field='resources' link='true' separator=', ' output='raw'][/types]"]</a>

==> Whereas types field='resources' is the name of your custom field (for the upload file).

Thank you

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.