Ordering News Items by "publishDate desc, createDate desc" does not work as it used to
I have a news listing on my website, which I based on the standard Umbraco templates that were around at the time I first built the site.
News items have a createDate property (the built-in umbraco standard for a document), plus a custom date field called publishDate.
The idea is that if the editor does not specify a publishDate, the document's createDate will be used; otherwise, the publishDate will be preferred.
The code includes the following:
// Find all pages with document type umbNewsItem under this page.
// Then order them, first by publishDate (a property the editor can explicitly set on the news item)
// and then by createDate, which is set by Umbraco automatically when a page gets created.
var newsItems = @CurrentPage.sqdNewsItems.OrderBy("publishDate desc, createDate desc");
This should be fairly standard stuff. When I first created the site, I verified that it all worked OK. I tested with news items with and without publishDates explicitly set.
But today, one of my editors alerted me that news items which did not specify a publishDate; which were otherwise published, (and available on their direct URLs) were not listed in the news listing page at all - and thus un-discoverable.
I recently upgraded to 7.6.1 and I had to change quite a bit of other code on my site to take account of API changes. Has something else changed to make the above invalid?
'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'ThenBy'
The stranger thing is that my staging site (which is supposed to be functionally identical) doesn't have the original problem - dates are sorted as expected. Nor do I have the issue on my development machine. (I do all my development in visual studio, then I sync to the staging site, and finally prod. I use uSync to synchronise the document types).
Ordering News Items by "publishDate desc, createDate desc" does not work as it used to
I have a news listing on my website, which I based on the standard Umbraco templates that were around at the time I first built the site.
News items have a createDate property (the built-in umbraco standard for a document), plus a custom date field called publishDate.
The idea is that if the editor does not specify a publishDate, the document's createDate will be used; otherwise, the publishDate will be preferred.
The code includes the following:
This should be fairly standard stuff. When I first created the site, I verified that it all worked OK. I tested with news items with and without publishDates explicitly set.
But today, one of my editors alerted me that news items which did not specify a publishDate; which were otherwise published, (and available on their direct URLs) were not listed in the news listing page at all - and thus un-discoverable.
I recently upgraded to 7.6.1 and I had to change quite a bit of other code on my site to take account of API changes. Has something else changed to make the above invalid?
Hi Nick
Did you try ThenBy?
var newsItems = @CurrentPage.sqdNewsItems.OrderBy("publishDate desc").ThenBy("createDate desc");
Thanks,
Alex
When I do that, I get this error:
The stranger thing is that my staging site (which is supposed to be functionally identical) doesn't have the original problem - dates are sorted as expected. Nor do I have the issue on my development machine. (I do all my development in visual studio, then I sync to the staging site, and finally prod. I use uSync to synchronise the document types).
What about data? Are databases different between environments?
Maybe some issue with Umbraco index? Did you try to republish all site?
The databases should be identical between the two. However, I am wondering whether something has gone wrong. I'm not really sure how to check.
Yes, I've done a re-publish of the whole site. Is there any other way to bump the index?
Hi Nick
Can you show all code of your partial?
Let's rewrite it to strongly typed models.
Thanks,
Alex
is working on a reply...