Sort by LastEdited shows wrong order for the anonymous user.

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

4.4.1@stable:

Question:

Filter a specific page type by ClassName from the SiteTree, and sorted the “LastEdited“ by the DESC.
Loop the $LatestUpdates on the template, the order of last edited pages are not correct. But if you logged in and view the page with ?stage=Stage in your URL, the page is showing the correct order.

function getLatestUpdates()
    {
        $pages = SiteTree::get()
        ->filter('ClassName', 'App\\PageTypes\\ContentPage')
        ->sort('LastEdited', 'DESC')
        ->limit(3);
        return $pages;
    }

Please have a look, is there anything wrong with my code?

Sounds like it might be something going on with Versioning.

Do you see the same results with:

return ContentPage::get()->sort('LastEdited', 'DESC')->limit(3);

?

Failing that, you might try something like:

return Versioned::get_by_stage(ContentPage::class, 'Live', '', 'LastEdited DESC', '', 3);

(completely untested!)

Thanks @DorsetDigital
But I found the issue is not from the Page, because I created this function on the elemental block, and the elemental block is on the page. And the published changes from the elemental block wont make its parent page published and updated the ‘LastEdited’ neither.