Hello,
I’m using Horizon and I have an event cards section, that displays blog posts as events. How would I set the sort order of the blogs from the default of publish date, to a metafield that contains a date.
The idea being that the event thats the nearest in time, will display first.
Avoiding apps, need the liquid solution please.
Many thanks,
@VisitIlminster I don’t have the exact code of the event cards section and don’t know the namespace for your meta-field too but I can give you the generic code to sort your blog posts as events. Considering your metafield has following parameters:
- Namespace: custom
- Key: event_date
- Type: date_and_time or date
{% assign sorted_articles = blog.articles | sort: "metafields.custom.event_date" %}
{% for article in sorted_articles %}
## {{ article.title }}
{{ article.metafields.custom.event_date.value | date: "%B %d, %Y" }}
{{ article.excerpt }}
{% endfor %}
How do I send you the code to view? I tried adding your code to the container, but this then applied the same dates to all cards, duplicate all events, for each occuring date.
@VisitIlminster Can you share the code here so I can look at it?
I tried to post the code, but it keeps being removed.
Unfortunately, I’m still looking for a solution to this.