From 72ce9ec42e871321b09f219dcad0bb8c8e54b11c Mon Sep 17 00:00:00 2001 From: Marco Boom Date: Tue, 2 May 2017 14:00:33 +0200 Subject: [PATCH] Sort Post Object if multiple by defined position in Wordpress --- src/Field/PostObject.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Field/PostObject.php b/src/Field/PostObject.php index fc004fc..a50e435 100644 --- a/src/Field/PostObject.php +++ b/src/Field/PostObject.php @@ -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); }