Pods: Displaying more than one field in "Display Field in Selection List"

Created on 4 Feb 2016  路  9Comments  路  Source: pods-framework/pods

Hi,

Take a look at the picture. It says more than thousands words:
firstname and lastname in display field

I have done some research here on Github, and the forums. And found some topics. I first thought it should work, but on this topic it is just a secondary function call: http://pods.io/forums/topic/listing-multiple-select-relationship-fields-in-templates/

Another topic about the subject: http://pods.io/forums/topic/displaying-more-than-one-field-in-selection-lists-ui-configuration/

Is this possible guys?

Edit: also {@firstname}{@lastname} does not work.

Focus Help Wanted Need Votes Enhancement Support

Most helpful comment

Just to mention, the "{@firstname} 'some text' {@lastname}" solution would have solved my use case today. So, an up vote on the ability to use two magic tags.

All 9 comments

Afaik currently only via a filter
https://github.com/pods-framework/pods/issues/1240#issuecomment-33125034

Hi thanks @quasel!

I had them configured as an Ajax pick field type. So I ended up with this code:

add_filter('pods_field_pick_data_ajax_items', 'show_first_and_lastname_in_pick_field', 1, 6);

function show_first_and_lastname_in_pick_field($items, $name, $value, $field, $pod, $id){
        if ($name == "customer") {
            foreach ( $items as $key => &$data ) {
                if( $data['id'] ){
                    $p = pods('customer', $data['id']);
                    $firstname = $p->field('voornaam');
                    $lastname = $p->field('achternaam');
                    $data['text'] = $firstname . ' ' . $lastname;
                }
            }
        }
        return $items;
    }

Works perfect!

Is it possible to target only a Specific relationship field with that filter, @quasel? In looking at it, that would apply to all, right? Or are you controlling that with the if ($name checks... ie for configuring multiple field select relationships with one filter?

yep you need the IF condition for that - multiple IF statements would allow to configure that for mor than one ...

Just to mention, the "{@firstname} 'some text' {@lastname}" solution would have solved my use case today. So, an up vote on the ability to use two magic tags.

I also would have liked this.

I did not remember that I created this code years ago. I just used my own code again in this issue to fix this issue for a customer, an update on this one would be great! :-)

Also I slightly changed the code, otherwise the values are not shown:

add_filter('pods_field_pick_data_ajax_items', 'show_first_and_lastname_in_pick_field', 1, 6);

function show_first_and_lastname_in_pick_field($items, $name, $value, $field, $pod, $id){
        if ($name == "customer") {
            foreach ( $items as $key => &$data ) {
                if( $data['id'] ){
                    $p = pods('customer', $data['id']);
                    $firstname = $p->field('firstname');
                    $lastname = $p->field('lastname');
                    $data['text'] = $firstname . ' ' . $lastname;
                    $data['name'] = $firstname . ' ' . $lastname; // <------- - ADDED - IS NOW NEEDED 
                }
            }
        }
        return $items;
    }

Hi everyone, but hasn't this been resolved yet?

@negiot This issue is labeled "Need Votes" and is still open. Pending priority and todo list.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jnaklaas picture jnaklaas  路  3Comments

JoryHogeveen picture JoryHogeveen  路  3Comments

Ramoonus picture Ramoonus  路  5Comments

wpstudio picture wpstudio  路  6Comments

HmCody picture HmCody  路  6Comments