Multiple Fields in a Drop Down Relationship Pick List Using a Filter

When you need to change what is shown in the drop-down Select Field in a Relationship, you can use this method to base the value on other values in Post Type.

Useful when you need to change the value of a select field based on other fields in your Pod.

function pods_RELPODNAME_pick_data($data, $name, $value, $options, $pod, $id){
	if ($name == "pods_field_RELPODNAME") {
    	foreach ($data as $dataid => &$value) {
        	if($dataid){
                $p = pods('RELPODNAME', $dataid);
                $name = $p->display('name');
                $relfield = $p->display('RELATIONSHIPFIELD.name');
                $value = $relfield . ' - ' . $name;
            }
        }
    }
	return $data;
}
add_filter('pods_field_pick_data', 'pods_RELPODNAME_pick_data', 1, 6);

So let’s say, you are in a car pod, and want to select a tire type, but you want to display the tire manufacturer’s name in the list for easy browsing – Manufacturer in this case is a relationship field of Tire

You’d replace RELPODNAME with tires and RELATIONSHIPFIELD.name with manufacturer.name.

Submitted by Markus Stefano on GitHub

Questions