ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Best way to sort by custom secondary date, not by entry date

September 24, 2012 11:06pm

Subscribe [1]
  • #1 / Sep 24, 2012 11:06pm

    benek

    189 posts

    I have a directory where some entries pay to be “premium” and listed above other free entries. As a secondary sort level, all the premium entries are ordered by who became premium first, so older premium members retain their top spot when new ones are added.

    I’m using a simple text input custom field with the “premium date” formatted like 2012-09-24. Whenever a new entry becomes premium I type the date in there. I then use this field to sort like this

    orderby="is-premium|premium-date" sort="desc|asc"

    The problem with this is that entries with nothing entered into the premium date field showed above entries with a date, so I got around this by modifying the database to add a value of “0” to all empty fields with that field name. This made them come below all entries with any premium date.

    My ongoing problem is that all new entries that are created must have a “0” value typed into that field, and I’d prefer not to have to look at the field at all unless a date is required. There are already a bunch of new entries with the date field value forgotten and editing them after the fact is a huge inefficiency.

    I imagine there must be a batter way to do this. The problem I’m running into is that custom fields don’t allow you to specify a default value if the field is left blank. So regardless of the fieldtype empty fields will keep coming up above fields with a date specified.

    I need a field type that will allow automatically fill the field with a default “0” value if it’s left blank. My understanding is that if you limit a field to a number or decimal only is may create a default value of “0”. Is this correct? But entering dates into a number only field would be cumbersome and hard to read.

    Is there a date picker field that will allow for a default date?

    Is there a better way to do this that I’m not thinking of?

  • #2 / Sep 25, 2012 5:10pm

    Dan Decker

    7338 posts

    Hi benek,

    It sounds like you have to put quite a bit of work into managing this!

    I did some digging around looking for an extension that would add a default value, etc.

    Then I thought about the root problem you are having… entry order.

    I think it would be worth a look at Low Reorder. You can use it to build sets of ordered entries based on filters.

    Say a new premium author comes on, you add them to the filter in the proper order and Low Reorder takes care of the rest.

    Thoughts?

    Cheers,

  • #3 / Sep 25, 2012 6:01pm

    benek

    189 posts

    Hey Dan thanks for the reply.

    Firstly, I should have mentioned but I’m using Super Search, so this needs to be something I can add as part of my orderby string in search results.

    Secondly, at times I’m displaying entries from multiple channels at once. Last time I checked Low Reorder could only do one channel at a time. Maybe it has improved since I last looked but It doesn’t solve the problem anyway unless it provides some way to get that order data in my orderby string.

  • #4 / Sep 25, 2012 6:08pm

    benek

    189 posts

    OK I see now that Low Reorder has improved greatly since last time I looked at it! Turns out it’s now great for another project of mine, but doesn’t fix the situation above.

    Any other ideas?

  • #5 / Sep 26, 2012 5:34pm

    Kevin Smith

    4784 posts

    Going back to your original line of thinking then, if I were in your shoes, I would consider developing my own fieldtype for just this purpose. It could be as simple as a modified version of the text input fieldtype that assigns a default value (which would be “0”) if no value was entered.

    Would that do it?

  • #6 / Sep 26, 2012 5:37pm

    benek

    189 posts

    Yep that would do it I think. It’s essentially automating the process that I already have, which is fine. I just don’t know how to develop that. Probably over my head even though it’s simple.

  • #7 / Sep 27, 2012 2:29pm

    Kevin Smith

    4784 posts

    I think I might have something to help here. Be on the lookout for an email from me!

  • #8 / Sep 27, 2012 5:41pm

    benek

    189 posts

    Thanks Kevin,

    I’ve tested what you sent me and it looks perfect. One other thing I need a bit of help with:

    Can you help me write a query I can run that will look through all existing premium-date fields and if any of them are empty add a value of “0”? That would be the fastest way to update any older entries that not ordering properly, right?

  • #9 / Sep 28, 2012 2:02pm

    Kevin Smith

    4784 posts

    Sure, I can help there. Let me actually follow-up with you privately on that.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases