I'm not able to choose a field of a related pod to show. The direct database fields (of the related pod) I can show in the list, but not the related ones (so, these are related, to the related pod).
I'll give an example with some screenshots, because it sounds difficult like this :-)
I have a pod "employee", which had a related field to a WP user (an employee is a WP user and works for a certain company ... just one company = single select).
bi-directional relationship company <--> employees (1 company --> many employees)
Now, to select/show employees for a company, I want to show fields of the WP user (like display_name or user_login)
At this moment, on company level, I only see the emplyee ID's, which doesn't say much.
So, on company level, I want to show the employee with its name, which is not stored directly on "Employee" but on the "WP User".
Is that possible one way or another?
This is not yet available (traversing into relationships on fields) for this option. You can only use fields on that Pod (if it's an ACT), or fields on the object (for Post Types, Taxonomies, Media, Users, and Comments).
For now, you can use a solution like this:
ok, thanks for the info
Sorry to bother you again with this.
Have small questions regarding that example. Might be very stupid questions ... I'm quite new to this.
some assumptions: are these correct?
ok thanks
if ($name == "pods_field_teachers") { ...
thats where I see pods_field_teachers ... but it should be "teachers"
Try checking $options[ 'name' ] instead
As I keep stumbling over this issue, here's a copy paste solution :
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.
Hi, I used this patch: https://github.com/pods-framework/pods/tree/feature/1240-displayfield and it solved the following for me.
SETUP
POD A: custom post type with text field "label"
POD B: custom post type with relationship field named "group" related to POD A and the relationship field's "Display Field in Selection List" set to {@label}
CURRENT RELEASE
On the POD B edit screen, the dropdown options all said "(No Title)"
WITH THIS PATCH
On the POD B edit screen, the dropdown displayed the values of the label field as expected.
Thanks!!
fixed via #2654
This has not been fixed. This is the question about reaching across in a Relationship Field to a connected table's relationship field and showing values from THAT table.
Per 'Jim True' on Slack, after trying to use it here, this isn't actually fixed. Trying to get the string via a relationship in the target still fails.
The workaround for this one is as indicated above by @mastef
https://github.com/pods-framework/pods/issues/1240#issuecomment-33125034
filter for the new DFV List View fields pods_field_dfv_data
Scenarios
as listed in #4534 each of them behaves entirely different in terms of field names or number of parameters or ...
Why do we need a unified approach? Well for some more advanced solutions it's not always a "single" field that identifies a pod entry e.g a person can have a first and family name. Or think about bridge tables that connect multiple related pods… yes we could go and use an additional field - hello "post_title" but that feels bit weird although it solves/fixes some other WP related things ;) like Permalinks and stuff ^^
I think this could need an additional discussion as to how to deal with the post_title if it's deactivated or to maybe offer an option to set it like Display Field in selection list! ( side not if pods()->save() is used providing just one field a composed post_title using pods_api_pre_save_pod_item_ might fail as it only provides the value for the saved field )
currently it all starts here - https://github.com/pods-framework/pods/blob/edc95828c1fc94f8003d0fc8d2f3ac7bde69493b/classes/fields/pick.php#L2080
but that's not easy to filter as it just helps preparing the query as far as I understand it :D
just stumbled on another one #4522 - we maybe should add a sane default if no post_title is set!
This can be done using magic tags: {@user_login}.
Most helpful comment
As I keep stumbling over this issue, here's a copy paste solution :
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
RELPODNAMEwithtiresandRELATIONSHIPFIELD.namewithmanufacturer.name.