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.

Showing ONLY expired entries for a day

December 27, 2007 6:02pm

Subscribe [3]
  • #1 / Dec 27, 2007 6:02pm

    TheBrad

    48 posts

    Is it possible to display only weblog entries which expired on a given day? If not using existing tags, can someone help me—a bear of very little brain—construct a query to do it?

    I ask because I am trying to create a weblog database of people, using the entry date for their birthday and the expiration date, rather literally, as the date of their death.

    I would then like to use this information to make a page that displayed individuals in the database born on that day (MM/DD, in any year) and individuals who died on that day (again, MM/DD, in any year).

    A little help?

  • #2 / Dec 28, 2007 2:22am

    ExpressionEngineer

    148 posts

    Hey, the stop_before param might be what you’re looking for.

    In short, something like this, but read the docs I linked to for more details.
    show_expired=“yes” stop_before=”{current_time format="%Y-%m-%d %g:%i %A"}”

  • #3 / Jan 02, 2008 11:56am

    Robin Sowell

    13255 posts

    I think it may be trickier than that.  Show expired will get them to show- but it won’t prevent non-expired from showing.  Might could remove those via a conditional based on expiration date, though.  Not lean and it would jam up pagination, but if you don’t have a ton of entries, it might work.

    Otherwise- I think I’d go with a query.  If you need to poke that option, say the word and I’ll shift this over to ‘How to’ for brainstorming the query.

  • #4 / Jan 02, 2008 5:47pm

    TheBrad

    48 posts

    Well, I guess I’m definitely in the market for a query and, as one of the SQL-challenged, I’d welcome all the how-to help I can get. Thanks!

  • #5 / Jan 03, 2008 11:23am

    Robin Sowell

    13255 posts

    OK- let’s shift this over to ‘how to’- and I’ll show you a cheat.  We’ll do a tiny query in php to collect the ids, then echo that back in the entry_id parameter of the weblog tag- so it only pulls those entries.  The query bit is actually really easy.  The localization/time stuff?  Not so much.  Are you localizing?  In other words, can members set their own localization?  If so- we’ll use the php here to figure out the correct localized time for ‘today’.

  • #6 / Jan 03, 2008 11:59am

    TheBrad

    48 posts

    No, I’m not localizing. All entries will be normalized to a single time zone.

  • #7 / Jan 03, 2008 12:24pm

    Robin Sowell

    13255 posts

    OK- I don’t have a great way to test, but this isn’t throwing errors.  See if it works for you- should only pull stuff with an expiration date sometime today- and it’s gmt.

    <?php
    global $DB, $LOC;
    
    $ids = 1;
    $month = date('m');
    $day = date('d');
    $year = date('Y'); 
    
    
    $start_time = $LOC->set_gmt(mktime(0, 0, 0, $month, $day, $year));
    $end_time = $LOC->set_gmt(mktime(23, 59, 59, $month, $day, $year)); 
    
    $query = "SELECT entry_id, expiration_date FROM exp_weblog_titles WHERE expiration_date >= $start_time AND expiration_date <= $end_time";
    
    
    $results = $DB->query($query);
    
        if ($results->num_rows > 0)
        {
            foreach($results->result as $row)
            {
                $ids[] = $row['entry_id'];
    echo $row['expiration_date'].'
    ';
            }
        $ids = explode('|', $ids);
        }
    
    echo $ids;
        
    ?>
    
    
    
    {exp:weblog:entries entry_id="<?php echo $ids; ?>"}
    {title}
    {/exp:weblog:entries}

    Note- php has to be turned on for the template and parsed on input.  Also- it defaults to showing id 1 if there are no expired entry today.  For some reason, putting in 0 as the default ends up ignoring the entry id parameter.

    Anyway- give it a shot.

  • #8 / Apr 03, 2008 11:34pm

    TheBrad

    48 posts

    Anyway- give it a shot.

    After having to put this project aside for a while, I came back to it today. This doesn’t work for me, although it’s possible I’m being somehow dense about it.

    I created a test weblog, called “test” and entered a few dummy posts with assorted expiry dates, including today. Put the code above into a template, set it to parse PHP on input.

    The resulting output is just this:

    1207293000
    Array

    This is on EE 1.6.3, build 20080319.

    Any thoughts?

  • #9 / Apr 04, 2008 5:56am

    Ingmar

    29245 posts

    $ids is an array, not a variable. Try

    <?php var_dump($id); ?>

    to see what I mean.

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

ExpressionEngine News!

#eecms, #events, #releases