acf_build_bidirectional_relationship_field_target_args()
Build valid fields for a bidirectional relationship for select2 display
Хуки из функции
Возвращает
Массив.
Использование
acf_build_bidirectional_relationship_field_target_args( $results, $options );
- $results(массив) (обязательный)
- The original results array.
- $options(массив) (обязательный)
- The options provided to the select2 AJAX search.
Список изменений
| С версии 6.2 | Введена. |
Код acf_build_bidirectional_relationship_field_target_args() acf build bidirectional relationship field target args ACF 6.4.2
function acf_build_bidirectional_relationship_field_target_args( $results, $options ) {
$valid_field_types = apply_filters( 'acf/bidirectional/supported_target_field_types', array( 'relationship', 'post_object', 'user', 'taxonomy' ) );
$field_groups = array_filter(
acf_get_field_groups(),
function ( $field_group ) {
return $field_group['active'];
}
);
$valid_fields = array();
foreach ( $field_groups as $field_group ) {
$fields = acf_get_fields( $field_group );
foreach ( $fields as $field ) {
if ( in_array( $field['type'], $valid_field_types, true ) ) {
if ( empty( $valid_fields[ $field_group['title'] ] ) ) {
$valid_fields[ $field_group['title'] ] = array();
}
$valid_fields[ $field_group['title'] ][ $field['key'] ] = array(
'type' => $field['type'],
'label' => $field['label'],
);
if ( isset( $options['parent_key'] ) && $options['parent_key'] === $field['key'] ) {
$valid_fields[ $field_group['title'] ][ $field['key'] ]['this_field'] = true;
}
}
}
}
foreach ( $valid_fields as $field_group_name => $fields ) {
$field_group = array(
'text' => $field_group_name,
'children' => array(),
);
foreach ( $fields as $key => $data ) {
$field_group['children'][] = array(
'id' => $key,
'text' => $data['label'],
'field_type' => $data['type'],
/* translators: %s A field type name, such as "Relationship" */
'human_field_type' => sprintf( __( '%s Field', 'acf' ), acf_get_field_type_prop( $data['type'], 'label' ) ),
'this_field' => ! empty( $data['this_field'] ),
);
}
$results['results'][] = $field_group;
}
return $results;
}