Lookup Field - File Names

By: Peter S | Asked: 06/06/2025
ForumsCategory: Code HelpLookup Field - File Names
Peter S asked 5 months ago

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:

frm_filtered_lookup_options

Thanks!

1 Answers
Victor Font Staff answered 5 months ago

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

Peter S
replied 5 months ago

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;
}

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right