admin管理员组文章数量:1391969
I have a question. I have 2 types of custom field group: Group A and Group B. All I am using ACF. In Group A, I have field name course_trainer. This field type is a User type and can have multiple values.
In Group B, I have field name class_trainer.This field type is a Select type and cannot have multiple value. This field will display data from field course_trainer. Basically, I used dynamic select for data to display at class_trainer.
If course_trainer field type not using multiple values, I can manage to display the data but if field type can have multiple values, the data not display at all.
I create a function in function.php to display the dynamic select:
function acf_load_t_first_name2_field_choices($field) {
global $post;
//$post = $_GET['post'];
// reset choices
$field['choices'] = array();
// get the textarea value from options page without any formatting
$choices = get_field('t_first_name',$post->ID);
// loop through array and add to field 'choices'
if( is_array($choices) ) {
foreach( $choices as $choice ) {
$field['choices'][ $choice ] = $choice;
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=course_trainer', 'acf_load_t_first_name2_field_choices');
Can someone correct my codes? Please help me :(
I have a question. I have 2 types of custom field group: Group A and Group B. All I am using ACF. In Group A, I have field name course_trainer. This field type is a User type and can have multiple values.
In Group B, I have field name class_trainer.This field type is a Select type and cannot have multiple value. This field will display data from field course_trainer. Basically, I used dynamic select for data to display at class_trainer.
If course_trainer field type not using multiple values, I can manage to display the data but if field type can have multiple values, the data not display at all.
I create a function in function.php to display the dynamic select:
function acf_load_t_first_name2_field_choices($field) {
global $post;
//$post = $_GET['post'];
// reset choices
$field['choices'] = array();
// get the textarea value from options page without any formatting
$choices = get_field('t_first_name',$post->ID);
// loop through array and add to field 'choices'
if( is_array($choices) ) {
foreach( $choices as $choice ) {
$field['choices'][ $choice ] = $choice;
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=course_trainer', 'acf_load_t_first_name2_field_choices');
Can someone correct my codes? Please help me :(
Share Improve this question edited Mar 4, 2020 at 8:50 user3239674 asked Mar 4, 2020 at 7:22 user3239674user3239674 134 bronze badges1 Answer
Reset to default 0Can you try this amendment and see if $field is returning as you expect?
$field['choices'][] = $choice;
本文标签: advanced custom fieldsACF Dynamic select not showing data
版权声明:本文标题:advanced custom fields - ACF Dynamic select not showing data 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744697736a2620382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论