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"> ' . end( explode( '/', $value ) ) . '<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.
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]);
...