diff --git a/classes/Pods.php b/classes/Pods.php index eb3508fd65..dc34e94abb 100644 --- a/classes/Pods.php +++ b/classes/Pods.php @@ -483,29 +483,37 @@ public function input( $field, $input_name = null, $value = '__null' ) { * @since 2.0 */ public function fields ( $field = null, $option = null ) { - // No fields found - if ( empty( $this->fields ) ) + + $field_data = null; + + if ( empty( $this->fields ) ) { + // No fields found $field_data = array(); - // Return all fields - elseif ( empty( $field ) ) + } elseif ( empty( $field ) ) { + // Return all fields $field_data = (array) $this->fields; - // Field not found - elseif ( !isset( $this->fields[ $field ] ) ) + } elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) { + // Field not found $field_data = array(); - // Return all field data - elseif ( empty( $option ) ) - $field_data = $this->fields[ $field ]; - else { + } elseif ( empty( $option ) ) { + // Return all field data + if ( isset( $this->fields[ $field ] ) ) { + $field_data = $this->fields[ $field ]; + } elseif ( isset( $this->pod_data['object_fields'] ) ) { + $field_data = $this->pod_data['object_fields'][ $field ]; + } + } else { // Merge options - $options = array_merge( $this->fields[ $field ], $this->fields[ $field ][ 'options' ] ); - - $field_data = null; + if ( isset( $this->fields[ $field ] ) ) { + $options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] ); + } elseif ( isset( $this->pod_data['object_fields'] ) ) { + $options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] ); + } // Get a list of available items from a relationship field if ( 'data' == $option && in_array( pods_var_raw( 'type', $options ), PodsForm::tableless_field_types() ) ) { $field_data = PodsForm::field_method( 'pick', 'get_field_data', $options ); - } - // Return option + } // Return option elseif ( isset( $options[ $option ] ) ) { $field_data = $options[ $option ]; }