Skip Navigation

[Resolved] Displaying data from a FILE custom field type

This support ticket is created 2 years, 9 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 2 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2122863

I have a file field in my custom post type. I have a custom shortcode that I use to generate the link that is displayed on my custom post template.

// START my_post_files_func
function my_post_files_func($atts){
$atts = shortcode_atts( array(
'field' => '',
), $atts );

$field = $atts['field'];
if ( ! $field ) return;

$values = get_post_meta( get_queried_object_id(), $field, $label, false );

$out = "";
foreach( $values as $value ){
$out .= '<i class="fad fa-download"> <a href="' . $value . '" download>' . end( explode( '/', $value ) ) . '</a><br />';
}

return $out;
}
add_shortcode( 'post_files', 'my_post_files_func' );
// STOP my_post_files_func

it is triggered like this: [post_files field="wpcf-ib-product-documentation"]

What I would like to know is this ... how can I get it to display the WordPress "TITLE" value from the media gallery?

I cannot for the life of me figure out how to get that value displayed instead of the filename.

thx.

#2123139

Hello,

You can get the media title from image URL, for example:

...
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $value ));
$title = get_the_title($attachment[0]);
...
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.