Lookup Image Field

By: P Galloway | Asked: 07/07/2022
ForumsCategory: How-toLookup Image Field
P Galloway asked 2 years ago
Form A contains information on inventory. Form B is to select specific items. On form B the user is selecting an item then the lookup fields are watching the item field. One of the lookup fields is an image. I want the image to be displayed and not the ID. See attached.  Solutions?
Attachments
Michael ClarkMichael Clark replied 2 years ago

Since form fields have been recently expanded to support a wide range of shortcodes, maybe a view with a filter for the current record and the standard show image would work?

1 Answers
Best Answer
Walter JonesWalter Jones answered 2 years ago
I don't believe you will be able to show the actual image through the form field.  You could show the URL of the image, and perhaps your users could click the link to view the image.  That code is here:  
add_filter( 'frm_filtered_lookup_options', 'change_lookup_options', 10, 2 );
function change_lookup_options( $options, $args ) {
    if ( $args['field']->id === '25' ) { // change 25 to the id of the field in the other form
        foreach ( $options as $k => $option ) {
            $options[ $k ] = wp_get_attachment_url( $option );
        }
    }

    return $options;
}
Bobby Clapp replied 2 years ago

Using Walters example to get the image URL you could set an change event via JS to throw that image URL into an HTML field and/or with some custom HTML.

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