diff --git a/src/AdvancedCustomFields.php b/src/AdvancedCustomFields.php index 9aad0d8..2801104 100644 --- a/src/AdvancedCustomFields.php +++ b/src/AdvancedCustomFields.php @@ -55,6 +55,6 @@ public function __call($name, $arguments) $field = FieldFactory::make($arguments[0], $this->post, snake_case($name)); - return $field->get(); + return $field ? $field->get() : null; } } diff --git a/src/Field/FlexibleContent.php b/src/Field/FlexibleContent.php index bb49b9b..b207f9c 100644 --- a/src/Field/FlexibleContent.php +++ b/src/Field/FlexibleContent.php @@ -97,7 +97,9 @@ protected function fetchFields($fieldName, Builder $builder) $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName); $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id); - $field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id)); + + $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post; + $field = FieldFactory::make($meta->meta_key, $post); if (!array_key_exists($id, $blocks)) { continue; diff --git a/src/Field/Repeater.php b/src/Field/Repeater.php index ec47626..0a2a459 100644 --- a/src/Field/Repeater.php +++ b/src/Field/Repeater.php @@ -97,7 +97,10 @@ protected function fetchFields($fieldName, Builder $builder) foreach ($builder->get() as $meta) { $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName); $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id); - $field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id)); + + $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post; + $field = FieldFactory::make($meta->meta_key, $post); + $fields[$id][$name] = $field->get(); }