Another related blog post question - how to order by publish date?

Hello I am trying to get related posts working but i am having problem getting the most recent one to show in fact i am getting ones dated from out side the

here is my code

{% related_blog_posts limit=4, tags=tagList|join(‘,’), start_date=(year-2)|string~“-01-01”, end_date=“2023-04-10”, post_formatter=“recent_post_two” %}

However I am trying to return the most recent first in chronlogical order

Can some one also point me a resource to understand date function

Hey, @simonp :waving_hand: Thanks for your question. Have you tried adding the order_by parameter? — HubL functions. Here’s the definition “orderBy: order results by a specific property. For example, orderBy=email”

Example:

order_by="-publish_date"

Best,

Jaycee

Thanks for the reply i checked through Hubspot function page doesn;t seem have any mention of order_by. Is it something you add within the related_blog_posts parameter eg

{% macro recent_post_two(post) %}

{% set post = post|sort(False, False, ‘publish_date’)%} {{ post.publishDate|datetimeformat(‘%B %e, %Y’) }}

{% endmacro %}

{% related_blog_posts limit=4, tags=tagList|join(‘,’), start_date=(year-2)|string~“-01-01”, end_date=“2023-04-10”, post_formatter=“recent_post_two”, order_by=“-publish_date”

The only reference I can find about orderby is crm or hubDb references not related_blog_posts

Something I was looking is possible using the sort filter

RelatedBlogs|sort(False, False, ‘created’)

but not sure how apply via the related_blog_posts macro function?

@Jaycee_Lewis