Skip Navigation

[Resolved] add filename as field on front end

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

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

Assisted by: Luo Yang.

Author
Posts
#2482571
2022-10-24_13-11-55.png
2022-10-24_13-12-14.png
2022-10-24_13-17-17.png

I have aded a bunch of fields to my content template.
Now I need to add the filename of the featured image as well.
I followed the following post but seems I'm doing something wrong. It's not working.
https://toolset.com/forums/topic/display-file-name-of-uploaded-file-from-user-field/

I added the shortcode in settings, and then added the shortcode in the content template, but it's not displaying.

How do I do that? See attached images

Thanks in advance

#2482867

Hello,

I suggest you try these:
1) Modify the custom PHP codes as below:

add_shortcode( 'wpv_display_file_name', 'wpv_display_file_title_func');
function wpv_display_file_title_func($atts, $content) {
  
    global $wpdb;
    $atts = shortcode_atts( array(
        'url' => '',
        'info' => '', // title, alt or id return
    ), $atts);
    $res = '';
    $url = do_shortcode($content);
    $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;
    }
    if($atts['info'] == 'name'){
        $path_parts = pathinfo($url);
      	$res = $path_parts['filename'];
    }
    return $res;
}

More help:
hidden link

2) Use above shotcodes as below:
[wpv_display_file_name info="name"][wpv-post-featured-image output="url" size="full"][/wpv_display_file_name]

#2483107

I am not a developer.
Could you guide me where I need to change this code in WP?
Will updates overwrite my code?

Thanks

#2483477

You can try these:
Dashboard-> Toolset-> Settings-> Custom Code,
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
find and edit existed custom codes as I mentioned above
https://toolset.com/forums/topic/add-filename-as-field-on-front-end/#post-2482867

And test again

If you need more assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem post URL of your screenshot:
https://toolset.com/wp-content/uploads/2022/10/2482571-2022_10_24_13_12_14.png

#2483915

I did everything you mentioned, but it is still did not working
hidden link

how can I give you access securely?

#2484281

I have enabled the private detail box, please provide your website credentials in it.

#2484997

Thanks for the details, you just need to activate that custom codes snippet, for example:
Dashboard-> Toolset-> Settings-> Custom Code, find the item "filename", click the link "Activate", see the result here:
hidden link