Skip Navigation

[Resolved] PDF Title vs File Name

This support ticket is created 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1762989

Following the thread here: https://toolset.com/forums/topic/give-titles-to-files-uploaded-in-repeating-field/

The solution works, but I would like to display the title vs the file name.

#1763095

Hello,

I assume we are talking about the "Title" setting in WordPress Media library.

If it is, it needs custom codes, for example:
1) Add below codes in your theme file functions.php:

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;

2) In single post content, display the attachment title with below shortcode:
[show_file_info url="[types field='test-file' output='raw'][/types]" info="title"]

Please replace test-file with your custom file field slug