Skip to content

Commit d65cbcd

Browse files
authored
[5.x] Ensure consistent order of get_content results (#11429)
1 parent 43866a4 commit d65cbcd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Tags/GetContent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Statamic\Contracts\Entries\Entry as EntryContract;
66
use Statamic\Facades\Entry;
77
use Statamic\Facades\Site;
8+
use Statamic\Query\OrderedQueryBuilder;
89
use Statamic\Support\Str;
910
use Statamic\Tags\Concerns\OutputsItems;
1011

@@ -58,6 +59,11 @@ private function entries($items)
5859
->where('site', $this->params->get(['site', 'locale'], Site::current()->handle()))
5960
->whereIn($usingUris ? 'uri' : 'id', $items);
6061

62+
// Ensure correct order of results
63+
if (! $usingUris) {
64+
$query = new OrderedQueryBuilder($query, $items);
65+
}
66+
6167
return $this->output($query->get());
6268
}
6369
}

tests/Tags/GetContentTagTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ public function it_gets_multiple_items_by_pipe_delimited_ids()
6161
);
6262
}
6363

64+
#[Test]
65+
public function it_maintains_order_of_multiple_items()
66+
{
67+
$this->assertParseEquals(
68+
'<First><Second>',
69+
'{{ get_content from="123|456" }}<{{ title }}>{{ /get_content }}'
70+
);
71+
$this->assertParseEquals(
72+
'<Second><First>',
73+
'{{ get_content from="456|123" }}<{{ title }}>{{ /get_content }}'
74+
);
75+
}
76+
6477
#[Test]
6578
public function it_gets_multiple_items_by_pipe_delimited_uris()
6679
{

0 commit comments

Comments
 (0)