Skip to Content

Sort a HubDB query by date

⚠️ Note that this post hasn't been updated for at least a year and the information may be outdated, proceed with caution! (Last updated: May 19, 2022)

Let's assume you have a HubDB table (ID 12345) with two columns: 

  • A date column (Date type) with the column name "date"
  • A title column (Text type) with the column name "title"

In your code, you can use the orderBy parameter to sort your table by a specific column (in this case, "date"), adding a minus symbol in front of it if you want to reverse the order. So your query parameters will either be "&orderBy=date" or "&orderBy=-date"

Using the hubdb_table_rows function, this looks something like this: 

 

See the Pen [Blog Post Example] Sort a HubDB query by date by Stephanie O'Gay Garcia (@stephanieogaygarcia) on CodePen.

 

Note: if you've somehow landed on this post looking for a way to sort the actual HubDB table, unfortunately, that's not possible as of the time of writing this post unless you do some hacky export/order on a spreadsheet/re-import. But be sure to upvote the idea here! In a recent update, HubSpot have said they're working on it so fingers crossed!

←  Previous Article

How to combine posts from multiple HubSpot blogs in a custom module

Next Article  →

Prevent editing in content editors in coded HubSpot templates

Contact

Get help from a HubSpot CMS Expert

  • Custom HubSpot themes and reusable and easy-to-use HubSpot templates and modules
  • Technical support and guidance on the HubSpot CMS