Skip Navigation

[Resolved] Displaying File Name/Title uploaded from Admin

This support ticket is created 5 years, 8 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 1 reply, has 2 voices.

Last updated by Minesh 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1234253

Tell us what you are trying to do? I will be building sites that require admin users to upload accompanying documents in the back end. I want to display on the front end the Field title of the uploaded file. For example, the CPT is Meeting and two file fields are Meeting and Agenda. After each meeting, there are Agenda and Minutes Documents. Once the documents pass approval, the organization must upload the documents to the site via the backend so they are accessible to the public. I can upload the documents but can’t get the files (titled Agenda and Minutes) to show on the CPT detail page. I have to hard Code the file link in the editor.

Is there a similar example that we can see?
Here is a link to a site I’ve built to show you what I’m referring to: hidden link

The meetings list is built using Types but I have to use the Editor to hardcore the Agenda and Meetings links on the Read More page.

What is the link to your site?
hidden link

This is one of many. The backend feature will operate the same across multiple sites so if I figure this one then I’ll be able to replicate it on multiple sites.

#1234390

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - to display the uploaded file title you need to add a custom shortcode that should return the uploaded file title.

For example:
- Please try to add following shortcode to your current theme's functions.php file OR
- Custom Code section provided by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_shortcode( 'show_file_info', 'func_show_file_info');
function func_show_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'){
        $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;
}

Call the function as:

[show_file_info  url="[types field='your-field-name' output='raw'][/types]"  info="title"]