Order collection by date added to collection

I have a manual collection called “Back in Stock”. Items are added whenever inventory total increases (via flow). Items are removed after they have been in the collection for 30 days (flow). The sort order is manual.

Right now new items are added to the back/end of the collection. I want them added to the front/start of the collection. Obviously, so that the more recent “back in stock” items appear on page 1.

If this can be done with code or flow I’m willing to try it. I’ve added date tags to orders in flow before but I don’t see a way to add date tags to products and I don’t see a way to sort via tag/date anyway.

I see these filters that may be useful?

https://shopify.github.io/liquid/filters/reverse/ (just do the opposite to what its doing now?)

https://shopify.github.io/liquid/filters/sort_natural/ (sort by some property similar to updated/modified/added to collection/tagged)

https://shopify.github.io/liquid/tags/iteration/ (reversed)

Any tips for a coding noob? Flow or editing theme (Dawn) works for me.

It seems like this post could be helpful:

https://community.shopify.com/post/708859

Intead of using ‘published_at’ use ‘updated_at’ (does an inventory change count as “updated_at” or would I need to change more than that?)

However I’m stuck on which section I should paste the code into? I only want it to affect this one collection. Not all collections.

Looks like you’re getting close. Create a new collection template, call it collection-by-update.liquid or what not, then edit your code there. Lastly, assign the collection where you want the code to execute to use that template.

Thanks. I did try that, but there’s just no way to code for “updated most recently” unfortunately. Reversing the order will only work per page, not for the entire list. I’ve spoken to them about it and they made a minor concession in allowing the manual sort to work better (there’s now a “move to top” button) but that’s all so far.