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.

Sort ascending by expiration date, but exclude entries without an expiration date --> Need a query written

June 28, 2007 4:34pm

Subscribe [2]
  • #1 / Jun 28, 2007 4:34pm

    Oldtimer

    10 posts

    I’m trying to display entries in a weblog by their expiration_date with those expiring soon showing up first. I have some entries that don’t have an expiration date as the information isn’t publicly available. What we do when we write up the entry is just leave it blank. The sort and orderby commands work fine generally, but when I sort them by expiration_day in ascending order, the entries without an expiration date show up first.

    What I’d like to do is either exclude those entries from the list or make the entries show up at the bottom of the list. Any ideas? Solutions?

    Update:

    Looks like I need a query to get the job done. I think it should be a really quick job. Reply or send a message if you’re interested. I can offer a bit of payment too.

  • #2 / Jun 28, 2007 4:37pm

    Lisa Wess

    20502 posts

    You may need to do a conditional to see if the expiration date is blank, unfortunately that’ll mess with the limit (it’ll hide the entries, but if there are 5 entries without expiration dates, and you limit to 6, you’ll only see one entry).

    I’m going to pop this over to the how-to forum for now, you may need to use a plugin or query for this. You could also put in a feature request for this type of functionality.  Something like show_expired=“only”?

  • #3 / Jun 28, 2007 4:44pm

    Oldtimer

    10 posts

    That was fast… I was thinking conditional as well, but I didn’t think would work. If my code is:

    {exp:weblog:entries weblog="site_default" orderby="expiration_date" sort="asc" limit="10"}

    What conditional would I use? The logic for the if else conditional would be to show the entry if the expiry date isn’t blank, if it is blank don’t show it. What actions would be under each condition?

    {if expiration_date == 0}

    {if:else}

    {/if}

  • #4 / Jun 28, 2007 4:51pm

    Lisa Wess

    20502 posts

    Does testing if it’s blank work?  There is the variable but since it’s a bit of a special field, I’m actually not sure, as I’ve never had to test for it.  Try {if expiration_date == ""}No expiration date{/if} to test it? You have the data and setup so will be a lot easier for you to try this than for me right this moment; if you want me to do it then I’ll try it this evening.

    If that doesn’t work, then I suspect you’ll need a PHP/Query to do that, or a plugin.

  • #5 / Jun 28, 2007 5:15pm

    Oldtimer

    10 posts

    The test works. I have it on another page setup to display as follows:

    {if expiration_date == 0}
      Unknown
    {if:else}
      {expiration_date format='%F %j, %Y '}
    {/if}

    I’m not sure how/where I would integrate it into the weblog tag for sorting though. That’s where I’m stuck.

  • #6 / Jun 28, 2007 5:17pm

    Lisa Wess

    20502 posts

    Well, You could use a conditional to hide those entries, but it will mess up your limit as I described above, since they’d actually be included - just.. hidden.  So if you had a 20 limit and hid 5 because the expiration was blank, only 15 would show.  That may still be a viable option for you, but I’m not sure. 

    I think that to do this more properly - remove those before limiting - that you’d need to put together your own query.

  • #7 / Jun 28, 2007 5:22pm

    Oldtimer

    10 posts

    Yeah, the more I think about it, the more the conditional won’t work. Unexpired entries are all at the front, so the first few pages would just be blank. Anyone out there able to write the query for me? I can pay too, shouldn’t be much for a query I hope. Send me a message.

  • #8 / Jun 28, 2007 5:47pm

    Lisa Wess

    20502 posts

    If you want to hire someone, the job board is your best bet.  I would give the community some time on this - maybe edit the title to say what you need specifically at this point?

  • #9 / Jul 02, 2007 12:32pm

    Oldtimer

    10 posts

    Still looking for a query… anyone?

  • #10 / Jul 18, 2007 8:20pm

    Erskine

    46 posts

    Hi there.

    I needed to do the same thing. I came up with this simple query:

    <ul>
    {exp:query sql="SELECT weblog_id, title, url_title, expiration_date FROM exp_weblog_titles WHERE expiration_date != '0' AND weblog_id = '7' LIMIT 0,10"}
    <li><a href="/shows/review/{url_title}">{title}</a></li>
    {/exp:query}
    </ul>

    Where the ‘7’ is the weblog ID. This pumps out a list of ‘10’ (the “0,10” bit) items that do NOt have an expiration_date value of ‘0’.

    You just need to do some sort of orderby value to customize your order.

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

ExpressionEngine News!

#eecms, #events, #releases