Copied to clipboard

Flag this post as spam?

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


  • Phillip Ng 148 posts 250 karma points
    Aug 14, 2013 @ 22:54
    Phillip Ng
    0

    Order Blogs by Datepicker property first, then createDate

    Hi!

    Using v6.1.2. I have created a blog and initially set them to be ordered by the node's createDate. In order to allow posts to be back-dated, a date-picker property, "datePublished" has been added to the doc type. Now, I'd like to order the posts based on datePublished first, then by createDate. Some of the example out there don't seem to be working. For example, using

    dynamic posts = CurrentPage.Descendants("BlogPost").OrderBy("datePublished").And().OrderBy("createDate"); 

    gives me the "Object reference not set to an instance of an object" error. OrderBy("datePublished", "createDate") didn't seem to work either.

    Any suggestions? Thanks in advance for the help!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 14, 2013 @ 23:51
    Jeavon Leopold
    100

    Hi Phillip,

    Did you try .OrderBy("datePublished, createDate")?

    That syntax worked with DynamicNode but I've not tried it with dynamic Mvc (CurrentPage) so I'm not sure if its supported or not, if not then you should be able to use the ThenBy method with a typed object, something like

    dynamic posts = Model.Content.Descendants("BlogPost").OrderBy(x => x.GetPropertyValue<DateTime>("datePublished")).ThenBy(x => x.CreateDate); 
    

    Jeavon

  • Phillip Ng 148 posts 250 karma points
    Aug 15, 2013 @ 01:36
    Phillip Ng
    0

    The second option is what I needed. Thank you!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 15, 2013 @ 12:06
    Jeavon Leopold
    0

    Cool, I just amended a tiny typo above x.createDate should be x.CreateDate

Please Sign in or register to post replies

Write your reply to:

Draft