Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 0692dc6

Browse files
bpamiriclaude
andcommitted
feat: Use publishedAt for blog sort order and display date
Sort and display blogs by their actual publication date instead of COALESCE(post_created_date, createdAt). This ensures scheduled posts appear in chronological publish order and show correct dates in listings, RSS feeds, and Schema.org metadata. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3a6aca9 commit 0692dc6

9 files changed

Lines changed: 25 additions & 29 deletions

File tree

app/controllers/web/BlogController.cfc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ component extends="app.Controllers.Controller" {
186186

187187
} catch (any fallbackError) {
188188
// If even fallback fails, create empty result
189-
blogs = queryNew("id,title,slug,createdby,postDate,fullName,username,profilePicture", "integer,varchar,varchar,integer,date,varchar,varchar,varchar");
189+
blogs = queryNew("id,title,slug,createdby,publishedAt,fullName,username,profilePicture", "integer,varchar,varchar,integer,date,varchar,varchar,varchar");
190190
hasMore = false;
191191
totalCount = 0;
192192
hasError = true;
@@ -266,7 +266,7 @@ component extends="app.Controllers.Controller" {
266266
query = model("Blog").findAll(
267267
where="blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#' AND blog_posts.createdBy = #arguments.authorId#",
268268
include="User",
269-
order="COALESCE(post_created_date, blog_posts.createdat) DESC",
269+
order="publishedAt DESC",
270270
page = arguments.page,
271271
perPage = arguments.perPage
272272
),
@@ -320,7 +320,7 @@ component extends="app.Controllers.Controller" {
320320
var query = model("blog").findAll(
321321
where="blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#' AND (blog_posts.slug LIKE '#searchPattern#' OR blog_posts.title LIKE '#searchPattern#' OR blog_posts.content LIKE '#searchPattern#' OR fullname LIKE '#searchPattern#' OR email LIKE '#searchPattern#')",
322322
include="User, PostStatus, PostType",
323-
order = "COALESCE(post_created_date, blog_posts.createdat) DESC",
323+
order = "publishedAt DESC",
324324
page = page,
325325
perPage = perPage
326326
);
@@ -773,7 +773,7 @@ component extends="app.Controllers.Controller" {
773773
blogPosts = model("Blog").findAll(
774774
where="blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
775775
include="User",
776-
order="postDate DESC",
776+
order="publishedAt DESC",
777777
cache=10
778778
);
779779

@@ -827,7 +827,7 @@ component extends="app.Controllers.Controller" {
827827
query = model("Blog").findAll(
828828
where="blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
829829
include="User",
830-
order="COALESCE(post_created_date, blog_posts.createdat) DESC",
830+
order="publishedAt DESC",
831831
page = arguments.page,
832832
perPage = arguments.perPage,
833833
cache = 5
@@ -852,8 +852,8 @@ component extends="app.Controllers.Controller" {
852852

853853
var result = {
854854
query = model("Blog").findAll(
855-
where="blog_posts.post_created_date BETWEEN '#startdate#' AND '#enddate#' AND blog_posts.status='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
856-
order="postCreatedDate DESC",
855+
where="blog_posts.published_at BETWEEN '#startdate#' AND '#enddate#' AND blog_posts.status='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
856+
order="publishedAt DESC",
857857
include="User",
858858
returnAs="query",
859859
page = arguments.page,
@@ -864,7 +864,7 @@ component extends="app.Controllers.Controller" {
864864
};
865865

866866
result.totalCount = model("Blog").count(
867-
where="blog_posts.post_created_date BETWEEN '#startdate#' AND '#enddate#' AND blog_posts.status='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'"
867+
where="blog_posts.published_at BETWEEN '#startdate#' AND '#enddate#' AND blog_posts.status='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'"
868868
);
869869
result.hasMore = (page * perPage) < result.totalCount;
870870

@@ -887,7 +887,7 @@ component extends="app.Controllers.Controller" {
887887
var result = {
888888
query = model("Blog").findAll(
889889
where="blog_posts.id IN (#blogIdList#) AND categoryId = #category.id# AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
890-
order="createdAt DESC",
890+
order="publishedAt DESC",
891891
include="User,BlogCategory",
892892
returnAs="query",
893893
page = arguments.page,
@@ -927,7 +927,7 @@ component extends="app.Controllers.Controller" {
927927
var result = {
928928
query = model("Blog").findAll(
929929
where="blog_posts.id IN (#blogIds#) AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#'",
930-
order="createdAt DESC",
930+
order="publishedAt DESC",
931931
include="User",
932932
returnAs="query",
933933
page = arguments.page,

app/controllers/web/NewsController.cfc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ component extends="app.Controllers.Controller" {
4242
private array function getBlogs() {
4343
try {
4444
var blogQuery = model("Blog").findAll(
45-
select = "title, slug, content, postDate",
45+
select = "title, slug, content, publishedAt",
4646
where = "blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#now()#' ",
47-
order = "createdAt DESC",
47+
order = "publishedAt DESC",
4848
cache = 10
4949
);
5050

5151
var blogsArray = [];
5252

5353
for (var i = 1; i <= blogQuery.recordCount; i++) {
5454
// Convert to UTC
55-
var localDate = blogQuery.postDate[i];
55+
var localDate = blogQuery.publishedAt[i];
5656
var utcDate = dateConvert("local2utc", localDate);
5757

5858
// Format to ISO 8601: yyyy-mm-ddTHH:MM:SSZ

app/models/Blog.cfc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ component extends="app.Models.Model" {
2020
property(name="publishedAt", column="published_at", dataType="datetime");
2121

2222
property(
23-
name="postDate",
24-
sql="COALESCE(post_created_date, blog_posts.createdat)",
25-
label="Created At"
23+
name="postDate",
24+
sql="blog_posts.published_at",
25+
label="Published At"
2626
);
2727

2828
// Defining the foreign key
@@ -57,7 +57,7 @@ component extends="app.Models.Model" {
5757
where='statusid <> 1',
5858
include="User",
5959
maxRows=10,
60-
order="createdAt DESC",
60+
order="publishedAt DESC",
6161
cache=10
6262
);
6363
return blogs;
@@ -67,10 +67,6 @@ component extends="app.Models.Model" {
6767
* Computed property to get the correct post date.
6868
*/
6969
public function getDisplayDate() {
70-
if (NOT isEmpty(this.postCreatedDate)) {
71-
return this.postCreatedDate;
72-
} else {
73-
return this.createdAt;
74-
}
70+
return this.publishedAt;
7571
}
7672
}

app/views/layout.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
"headline": "#encodeForJavaScript(post.title)#",
315315
"description": "#encodeForJavaScript(metaDescription)#",
316316
"image": "<cfif isDefined("ogImage")>#ogImage#<cfelse>#getBaseUrl()#/img/wheels-logo.png</cfif>",
317-
"datePublished": "#dateFormat(post.postDate, "yyyy-mm-dd")#",
317+
"datePublished": "#dateFormat(post.publishedAt, "yyyy-mm-dd")#",
318318
"dateModified": "#dateFormat(post.updatedAt, "yyyy-mm-dd")#",
319319
"author": {
320320
"@type": "Person",

app/views/web/BlogController/partials/_blogList.cfm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<cfset authorUrl = "/blog/author/#blogs.username#">
1313
<cfset blogUrl = "/blog/#blogs.slug#">
1414
<cfset authorHxGet = "/blog/list/author/#blogs.createdby#?page=1&perPage=6&infiniteScroll=true">
15-
<cfset formattedDate = dateformat(blogs.postDate, 'MMMM DD, YYYY')>
15+
<cfset formattedDate = dateformat(blogs.publishedAt, 'MMMM DD, YYYY')>
1616
<cfset profileImageTag = '<img src="#gravatarUrl(blogs.email, 80)#&d=404"
1717
class="rounded-circle"
1818
style="width:2.5rem; height:2.5rem;"
@@ -74,7 +74,7 @@
7474
<p class="text--secondary fw-bold fs-14 m-0 author-name">
7575
#htmlEditFormat(blogs.fullName)#
7676
</p>
77-
<time class="text--lightGray fs-12 fw-medium" datetime="#dateformat(blogs.postDate, 'yyyy-mm-dd')#">
77+
<time class="text--lightGray fs-12 fw-medium" datetime="#dateformat(blogs.publishedAt, 'yyyy-mm-dd')#">
7878
#formattedDate#
7979
</time>
8080
</button>

app/views/web/BlogController/partials/_feed.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<title><![CDATA[#blogPosts.title#]]></title>
3030
<link>#application.env.application_host#/blog/#blogPosts.slug#</link>
3131
<dc:creator><![CDATA[#blogPosts.fullname#]]></dc:creator>
32-
<pubDate>#dateFormat(blogPosts.updatedAt, "ddd, dd mmm yyyy")# #timeFormat(blogPosts.updatedAt, "HH:mm:ss")# +0000</pubDate>
32+
<pubDate>#dateFormat(blogPosts.publishedAt, "ddd, dd mmm yyyy")# #timeFormat(blogPosts.publishedAt, "HH:mm:ss")# +0000</pubDate>
3333
<cfloop query="category">
3434
<category><![CDATA[#category.name#]]></category>
3535
</cfloop>

app/views/web/BlogController/show.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<div class="d-flex flex-wrap justify-content-center flex-grow-1 align-items-end gap-lg-5 gap-2 mt-3">
5656
<!-- Blog date -->
5757
<p class="fw-medium fs-12 text--lightGray mb-0">
58-
#dateformat(blog.getDisplayDate(), 'MMMM DD, YYYY')#
58+
#dateformat(blog.publishedAt, 'MMMM DD, YYYY')#
5959
</p>
6060

6161
<!-- Post status + Categories -->

app/views/web/HomeController/index.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
</div>
9595

9696
<div class="d-flex gap-2 justify-content-between align-items-center">
97-
<p class="fs-16 truncate fw-medium text--lightGray">#dateformat(blogs.postDate, 'MMMM DD, YYYY')# by #blogs.fullName#</p>
97+
<p class="fs-16 truncate fw-medium text--lightGray">#dateformat(blogs.publishedAt, 'MMMM DD, YYYY')# by #blogs.fullName#</p>
9898
<a href="/blog/#slug#"><button class="bg--primary text-nowrap fs-16 text-white rounded-2 px-3 py-1">Learn more</button></a>
9999
</div>
100100
</div>

app/views/web/HomeController/partials/_blogs.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99

1010
<div class="d-flex gap-2 justify-content-between align-items-center">
11-
<p class="fs-16 truncate fw-medium text--lightGray">#dateformat(blogs.postDate, 'MMMM DD, YYYY')# by #encodeForHTML(blogs.fullName)#</p>
11+
<p class="fs-16 truncate fw-medium text--lightGray">#dateformat(blogs.publishedAt, 'MMMM DD, YYYY')# by #encodeForHTML(blogs.fullName)#</p>
1212
<a href="/blog/#slug#"><button class="bg--primary text-nowrap fs-16 text-white rounded-2 px-3 py-1">Learn more</button></a>
1313
</div>
1414
</div>

0 commit comments

Comments
 (0)