Skip to content

Commit

Permalink
Merge pull request #35 from WP4Laravel/feature-relationship-sort
Browse files Browse the repository at this point in the history
Sort Post Object if multiple by defined position in Wordpress
  • Loading branch information
jgrossi authored May 3, 2017
2 parents c2e6ea9 + 72ce9ec commit cb1853a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Field/PostObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function process($fieldName)
$connection = $this->post->getConnectionName();

if (is_array($postId)) {
$this->object = Post::on($connection)->whereIn('ID', $postId)->get();
$this->object = Post::on($connection)->whereIn('ID', $postId)->get()->sortBy(function ($item) use ($postId) {
return array_search($item->getKey(), $postId);
});
} else {
$this->object = Post::on($connection)->find($postId);
}
Expand Down

0 comments on commit cb1853a

Please sign in to comment.