Hi,
I have a file upload field and a lookup field in another form.
The lookup field gives me the id number of each file, but does anyone have a code that would like me see the file name or title instead?
Formidable has this code that gives you an image instead of the ID but I really want the filename or title:
https://formidableforms.com/knowledgebase/frm_filtered_lookup_options/#kb-show-image-in-lookup-list-type
Thanks!
Use the WordPress wp_get_attachment_image function instead of wp_get_attachment_url. https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ function
Thanks that helped.
These codes worked:
//Show Image Title
add_filter( 'frm_filtered_lookup_options', 'show_lookup_image_title', 10, 2 );
function show_lookup_image_title( $options, $args ) {
if ( $args['field']->id === '20' ) { // Replace 20 with your actual field ID
foreach ( $options as $k => $option ) {
$title = get_the_title( $option );
$options[ $k ] = esc_html( $title );
}
}
return $options;
}
//Show Image Filename
add_filter( 'frm_filtered_lookup_options', 'show_lookup_image_filename', 10, 2 );
function show_lookup_image_filename( $options, $args ) {
if ( $args['field']->id === '20' ) { // Replace 20 with your actual field ID
foreach ( $options as $k => $option ) {
$file_path = get_attached_file( $option );
$filename = basename( $file_path );
$options[ $k ] = esc_html( $filename );
}
}
return $options;
}
Please login or Register to submit your answer