Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick Beaugié 28 posts 80 karma points
    Jul 09, 2017 @ 21:26
    Nick Beaugié
    0

    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?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jul 10, 2017 @ 09:28
    Alex Skrypnyk
    0

    Hi Nick

    Did you try ThenBy?

    var newsItems = @CurrentPage.sqdNewsItems.OrderBy("publishDate desc").ThenBy("createDate desc");

    Thanks,

    Alex

  • Nick Beaugié 28 posts 80 karma points
    Jul 10, 2017 @ 21:01
    Nick Beaugié
    0

    When I do that, I get this error:

    '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).

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jul 10, 2017 @ 21:18
    Alex Skrypnyk
    0

    What about data? Are databases different between environments?

    Maybe some issue with Umbraco index? Did you try to republish all site?

  • Nick Beaugié 28 posts 80 karma points
    Jul 10, 2017 @ 21:43
    Nick Beaugié
    0

    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?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jul 11, 2017 @ 08:00
    Alex Skrypnyk
    0

    Hi Nick

    Can you show all code of your partial?

    Let's rewrite it to strongly typed models.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft