如何更改某个Pod字段的输出?

Mer*_*glu 3 wordpress podscms

我有两个吊舱:courseteacher

每个course都有一个teacher

我使用短代码来构建一个表单来定义new course

[pods name='course' form='1' fields='name, teacher' ]
Run Code Online (Sandbox Code Playgroud)

当定义一个新的course,用户可以teacher为此选择course

默认情况下,nameteacher显示在下拉列表中。我想知道是否可以更改teachers下拉列表中的输出。

例如,除了name我想要显示某一领域,如locationteacher在下拉列表中。

使用Pods 2的内置短代码可以做到这一点吗?


更新:

按照Scott的指示,我解决了问题。我将解决方案写入注释部分,但是格式丢失了。在下面,我再次输入代码:

function pods_teacher_pick_data($data, $name, $value, $options, $pod, $id){
    if ($name == "pods_field_teachers") {
        foreach ($data as $id => &$value) {
            $p = pods('teacher', $id);
            $name = $p->display('name');
            $city = $p->display('profile.city.name');
            $value = $name . ' - ' . $city;
        }
    }
    return $data;
}

add_filter('pods_field_pick_data', 'pods_teacher_pick_data', 1, 6);
Run Code Online (Sandbox Code Playgroud)

Sco*_*ark 5

尚未内置,但您可以使用过滤器接管数据输出:pods_field_pick_data

$data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id );
Run Code Online (Sandbox Code Playgroud)

将过滤器添加到该过滤器应该可以更改下拉菜单或其他关系输入类型中显示的内容。

编辑:我刚刚添加了类似的过滤器来过滤自动填充数据。

$pick_data = apply_filters( 'pods_field_pick_data_ajax', array(), $field[ 'name' ], null, $field, $pod, 0, $data );
Run Code Online (Sandbox Code Playgroud)

该数组中的$ data实际上是完全设置的PodsData对象

编辑(2013年2月7日):

在Pods 2.3中,我添加了一个快速功能,该功能应简化添加自定义关系对象的过程。优先于覆盖现有关系或动态使用自定义简单定义。相当容易使用,请在https://github.com/pods-framework/pods/issues/1033上查看

$options = array(
    'group' => 'Special Relationships', // Whatever you want the selection group to be, defaults to label
    'simple' => false, // Whether this field is related by strings or integer IDs, integer IDs get stored in wp_podsrel, strings are stored in the field itself either serialized (meta-based) or json encoded (table-based)
    'data' => array( // Custom define the items to select from manually
        1 => 'Gravity Form 1',
        2 => 'Gravity Form 2'
    ),
    'data_callback' => 'get_custom_gravity_forms_list', // Provide a callback function to call to define the data (instead of setting 'data' above)
    'value_to_label_callback' => 'get_custom_gravity_forms_list', // Provide a callback function to define the data when called through PodsField_Pick::value_to_label
    'simple_value_callback' => 'get_custom_gravity_forms_list' // Provide a callback function to define the data when called through PodsField_Pick::simple_value
);

pods_register_related_object( 'gravity-form', 'Gravity Forms', $options );
Run Code Online (Sandbox Code Playgroud)