Blog posts page: custom sorting logic
See original GitHub issue🚀 Feature
Let’s be less opinionated and let users decide on the sorting logic.
Have you read the Contributing Guidelines on issues?
Yes
Has this been requested on Canny?
Requested on Discord
Motivation
Sorting by descending time works in almost all cases, but we shouldn’t assume that all users use the blog for time-based information. E.g., sort by alphabetical order? Sort by tags?
API Design
A new comparePosts plugin option, which accepts a function that is passed to the sorting algorithm:
And yes, it will receive the entire blog post, with all of its metadata and content.
Have you tried building it?
No; should be trivial
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (5 by maintainers)
Top Results From Across the Web
How to Arrange WordPress Posts in Any Order - WPMU Dev
Implement the custom sort order by modifying the main WordPress loop or building a custom loop and adding it to a sidebar widget...
Read more >How to sort blog posts by a custom field - HubSpot Community
We ran into this issue where we wanted to sort items from a blog based on the contents of a custom field/module we...
Read more >3 Ways to Re-Order WordPress Blog Posts - ThemeIsle
We cover three easy methods to re-order WordPress blog posts on the front-end. Step by step. Can be done on any blog or...
Read more >4 Easy Ways to Re Order Blog Posts in WordPress - YouTube
Do you want to change the order of your blog posts in WordPress? By default, WordPress shows posts in reverse chronological order where ......
Read more >5 Best Ways to Re-Order Posts in WordPress - Rank Math
You may need to rearrange a custom post type or want a WooCommerce product ... on your website may not always be to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@factoidforrest
In this case, you can use the date frontmatter to specify a time:
date: 2021-12-20T10:00:00ZWould you use
position: 3for such a post?IMHO what we are looking for here is rather a way to “pin” a blog post at the top (similar to GitHub issues somehow).
It’s also a common pattern among bloggers to have featured posts, and drive more attention to specific articles:
We could allow a plugin option to feature a list of posts, put them at the top, and maybe also add them to the blog sidebar to make them accessible from all blog pages.
Using
featured: truefrontmatter can also be nice, but not sure how to ensure an order in this case thoughUsing something like
position: numberis quite ambiguous, particularly when not all items have an explicit position, and we can’t prevent users to use the same position twice. + when adding a new blog post, do you really want to edit and offset all previously defined positions 😅If this position is only applied inside a single day, it would be a quite unintuitive option, and using an hour in frontmatter can be enough.
I don’t think it is quite as easy to add as another plugin, you have the contextual “next” and “previous” generation for the blog posts, which would be really awkward if they were sorted differently to the plugin sorting. I don’t have strong feelings about this feature, and I would personally add something looking more like enum:
My feeling is that the only strong use case here is reversing the order from oldest to newest