$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; } add_action( 'acf/fields/select/query/key=_acf_bidirectional_target', 'acf_build_bidirectional_relationship_field_target_args', 10, 2 ); /** * Renders the field settings required for bidirectional fields * * @since 6.2 * * @param array $field The field object passed into field setting functions. */ function acf_render_bidirectional_field_settings( $field ) { if ( ! acf_get_setting( 'enable_bidirection' ) ) { return; } acf_render_field_setting( $field, array( 'label' => __( 'Bidirectional', 'acf' ), 'instructions' => __( 'Update a field on the selected values, referencing back to this ID', 'acf' ), 'type' => 'true_false', 'name' => 'bidirectional', 'ui' => 1, ) ); acf_render_field_setting( $field, array( 'name' => 'bidirectional_notes', 'type' => 'message', 'message' => acf_get_bidirectional_field_settings_instruction_text(), 'conditions' => array( 'field' => 'bidirectional', 'operator' => '==', 'value' => 1, ), ) ); acf_render_field_setting( $field, array( 'type' => 'select', 'name' => 'bidirectional_target', 'label' => __( 'Target Field', 'acf' ), 'instructions' => __( 'Select field(s) to store the reference back to the item being updated. You may select this field. Target fields must be compatible with where this field is being displayed. For example, if this field is displayed on a Taxonomy, your target field should be of type Taxonomy', 'acf' ), 'class' => 'bidrectional_target', 'choices' => acf_build_bidirectional_target_current_choices( $field['bidirectional_target'] ), 'conditions' => array( 'field' => 'bidirectional', 'operator' => '==', 'value' => 1, ), 'ui' => 1, 'multiple' => 1, 'ajax' => 1, ) ); } /** * Returns the translated instructional text for the message field for the bidirectional field settings. * * @since 6.2 * * @return string The html containing the instructional message. */ function acf_get_bidirectional_field_settings_instruction_text() { /* translators: %s the URL to ACF's bidirectional relationship documentation */ $message = '
'; return $message; }