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.

How to show only expired entires on channel?

March 27, 2013 4:04am

Subscribe [2]
  • #1 / Mar 27, 2013 4:04am

    infomani28

    5 posts

    I want to show the entries which are expired or past(expired date). I tried the following code but doesn’t work and it show with future entries also. How to fix ti?

    1. doesn’t work

    {exp:channel:entries channel="english_channel" show_expired="yes" show_future_entries="no"  }
    
             {entry_date format="%Y %m %d"}-{expiration_date format="%Y %m %d"}
    
    {/exp:channel:entries}


    2. doesn’t work

    {exp:channel:entries channel="english_channel" show_expired="yes" show_future_entries="no"  stop_before={current_time format='%Y-%m-%d %H:%i'}}
    
    {entry_date format="%Y %m %d"}-{expiration_date format="%Y %m %d"}
    
    {/exp:channel:entries}

     

  • #2 / Mar 28, 2013 8:33am

    Tyssen

    756 posts

    Your second example with stop_before is the one you want, but if you look at the docs, they recommend setting the time value with PHP:

    <?php
            $current_time = $this->EE->localize->decode_date('%Y-%m-%d %H:%i', $this->EE->localize->now - 518400);
    ?>
    
    {exp:channel:entries channel="{my_weblog}" orderby="date" sort="desc" stop_before="<?php echo $current_time; ?>"}
  • #3 / Mar 28, 2013 9:28am

    infomani28

    5 posts

    Thanks for your reply. But I already tried that method which you given and it doesn’t work. It still shows the news which contain the expiry dates in future.

    Actually in admin end. there is 2 dates
    1. entry date
    2. expiry date.

    I want to show the records which contain simply expiry date < current date

  • #4 / Mar 28, 2013 5:42pm

    Tyssen

    756 posts

    You’ll probably have to use the query module instead then as the channel entries module is going to base all its date calculations on the entry_date.

  • #5 / Mar 29, 2013 2:05am

    infomani28

    5 posts

    Yes I used the following query for fetching expiry entries. It works fine.  But only drawback is the field_id_4 and field_id_5 need to change according to tables.

    <?php    
    $cur_time = time();
    $sql = "SELECT t.entry_id, ch.channel_name, t.title, t.entry_date, t.expiration_date, c.cat_id, f.field_id_4 as body, f.field_id_5 as image  FROM `exp_channel_titles` t INNER JOIN `exp_category_posts` c ON t.entry_id = c.entry_id INNER JOIN `exp_channels` ch ON t.channel_id = ch.channel_id INNER JOIN `exp_channel_data` f ON t.entry_id = f.entry_id WHERE c.cat_id = 8 AND ch.channel_name like 'news' AND t.expiration_date < ".$cur_time." AND t.site_id = ".$this->EE->config->item('site_id')." ORDER BY t.expiration_date DESC";
    ?>
    
    {exp:query limit="5" sql="<?php echo $sql; ?>"} 
    
    {title}
    {expiration_date format="%d/%m/%Y"}    
    {exp:strexp pattern="https://ellislab.com/asset/images/ent-partner-logo/" replace="" string="{image}" }
    {entry_date format="%d/%m/%Y"}  
    {body} 
       
                    {paginate}     {pagination_links}       {/paginate}                            
       
    {/exp:query}
  • #6 / Mar 29, 2013 3:16am

    Tyssen

    756 posts

    But only drawback is the field_id_4 and field_id_5 need to change according to tables.

    Sorry, don’t understand what that means.

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

ExpressionEngine News!

#eecms, #events, #releases