Sorting with dates is not correctly functioning with CMS Combine

Hi @Support-Luis, When I use CMS Combine attribute. I’m combining “News” and “Events” collection and would like to sort them out with dates.

Combining is working but when you check out the dates of events/news the sorting is not correctly functioning

Share Link

Thanks a lot

Hey @barrybaris! The best way would be to use CMS Sort along CMS Combine. Here is a link to a clonable we’ve made using this combo → CMS Sort + CMS Combine | Attributes.

You’ll have to add the custom code on the clonable page, the date field to your collection items and the corresponding CMS Sort setup for sorting by dates.

Let me know if you need help once you add these to the setup! :muscle:

This doesn’t seem to be sorting correctly. I cloned your example, gave it a date field, and it persists in sorting alphabetically (April, February, October, etc).

https://preview.webflow.com/preview/attributes-combos-6023a5?utm_medium=preview_link&utm_source=dashboard&utm_content=attributes-combos-6023a5&preview=d95839dd2f1f2810c76cc917ef458aee&workflow=preview

I had the same problem on my site: 2 CMS collections combined; sorting by name did work – sorting by “updated” (date) did not work. Turned out, that the date-format “D/M/YYYY” was the problem.

:ballot_box_with_check: Changed to “M/D/YYYY” (in a hidden field) solved the problem. Even with using weglot.

Simon

Thank you for sharing @simon1!

@_theclevernod let me know if Simon’s solution works for your project!

Hello! I am trying to acheive a similar solution here. I’m trying to combine three lists – “News”, “PDFs” and “Posts”. I have acheived success with the CMS Combine attribute, but am wanting to know the best way to sort them by most recent date to have them appear in a mixed list together.

I don’t have any intention to implement on-page sorting controls like buttons or dropdowns. What’s my best option for sorting here? Do I have to implement CMS Sort and auto-click a hidden button, or is there an easier way to implement this?

Hey @kristen.m.samuelsen! You can achieve this using the new API in Attributes V2. A sorting element is required, but it can be hidden—such as a button with the attribute fs-list-element="sort-trigger".

This is the API callback that will sort the list, simply modify the fieldKey and direction to suit your setup!

<script>
  window.FinsweetAttributes = window.FinsweetAttributes || [];
  window.FinsweetAttributes.push([
    'list',
    (listInstances) => {
      console.log('List Successfully loaded!');

      const [listInstance] = listInstances;

      listInstance.sorting.value.fieldKey = 'name';
      listInstance.sorting.value.direction = 'desc';
    },
  ]);
</script>

If you need any more help, you can open a new threa with your read-only link and I will take a look!