我有两个广告连播:course
和teacher
。
每个course
都有teacher
。
我使用短代码来构建表单来定义新的course
:
[pods name='course' form='1' fields='name, teacher' ]
定义新的course
时,用户可以为此teacher
选择course
。
默认情况下,name
的{{1}}会显示在下拉列表中。我想知道我是否可以在下拉列表中更改teacher
的输出。
例如,除了teachers
之外,我还要显示某个字段,例如下拉列表中name
的{{1}}。
这是否可以使用Pods 2的内置短代码?
更新
按照斯科特的指示,我解决了这个问题。我在解决方案部分编写了解决方案,但格式化已丢失。下面,我再次输入代码:
location
答案 0 :(得分:5)
尚未内置,但您可以使用过滤器接管数据输出:pods_field_pick_data
$data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id );
向该过滤器添加过滤器应该可以更改下拉列表或其他关系输入类型中显示的内容。
编辑:我刚刚添加了一个类似的过滤器,用于过滤自动完成数据。
$pick_data = apply_filters( 'pods_field_pick_data_ajax', array(), $field[ 'name' ], null, $field, $pod, 0, $data );
此数组中的$ data实际上是完全设置的PodsData对象
编辑(02/07/2013):
在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 );
答案 1 :(得分:0)
对于ajax,似乎需要使用一些不同的过滤器pods_field_pick_data_ajax_items,如下所示:
function pods_teacher_pick_data_ajax_items($items, $name, $null, $field, $pod, $id){
if ($name == "pods_meta_categorie" || $name == 'categorie') {
foreach ($items as &$item) {
$id = $item['id'];
$value = $item['text'];
$p = pods('dvd_categories', $id);
$code = $p->display('code');
$item['text'] .= ' - ' . $code;
}
}
return $items;
}
add_filter('pods_field_pick_data_ajax_items', 'pods_teacher_pick_data_ajax_items', 1, 6);
注意数组$ data和$ items的不同结构。 过滤pods_teacher_pick_data_ajax看起来很奇怪,对我来说没用,因为它不接受$ data数组。