Skip to content

Commit

Permalink
Merge pull request #20 from marcoboom/master
Browse files Browse the repository at this point in the history
Prevent double query and issue with non existing custom field
  • Loading branch information
jgrossi authored Mar 1, 2017
2 parents a25f480 + e09270b commit 58acb03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/AdvancedCustomFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion src/Field/FlexibleContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/Field/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 58acb03

Please sign in to comment.