Thanks for checking out Theadsensefamily-Online Money Making Forum In Nigeria!

You're currently viewing the forum as a guest which gives you limited browsing options, why don't you take 37 seconds and Sign up. Once you do you'll be able to enjoy all the great benefits of membership like
  • Ability to interact with other Theadsensefamily-Online Money Making Forum In Nigeria members
  • Create new discussions
  • Reply to existing discussions
  • Modify your profile to have a custom avatar, signature and more!
  • To many membership perks to list! Join today for free!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Set An Expiration Time For Posts on WordPress

Discussion in 'Help, Niches & Tutorials' started by Andy, Dec 8, 2017.

Loading...
  1. Andy

    Andy Vip Member Jr.Vip

    Messages:
    175
    Likes Received:
    90
    Trophy Points:
    44
    How to Set An Expiration Time For Posts on WordPress

    sometimes (for example, if you’re running a contest), you want to be able to publish a post and then automatically stop displaying it after a certain date. This may seem quite hard to do but in fact is not, using the power of custom fields.
    To do this Edit your theme and replace your current WordPress loop with this “hacked” loop:


    Code:
    <?php
    if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    $expirationtime = get_post_custom_values('expiration'); if (is_array($expirationtime)) { $expirestring = implode($expirationtime);
    }
    $secondsbetween = strtotime($expirestring)-time(); if ( $secondsbetween > 0 ) { // For example... the_title(); the_excerpt();
    }
    endwhile;
    endif;
    ?>
    To create a post set to expire at a certain daation as a key and your date and time as a value (with the format mm/dd/yyyy 00:00:00). The post will not show up after the time on that stamp.
     
    Last edited: Dec 8, 2017
    Abah Moses likes this.

Share This Page