Support

Account

Home Forums General Issues Using date picker to set post expiry date

Solved

Using date picker to set post expiry date

    • lerq

    • December 17, 2013 at 8:32 am

    Hi there,

    I’ve currently set a custom field up using the date picker to be used as an expiry date for the post.

    I’ve seen a number of plugins that change the status of a post to draft, but I’m looking to just hide the post from the category page (keeping the link alive if anyone goes straight to it).

    At the moment, I’m trying to compare the expiry date to today (converting it from a string along the way), but I can’t seem to get it to work.

    Do you have any ideas on how I can achieve this at all?

    Cheers,
    Lerq

    • Elliot

    • December 17, 2013 at 10:57 am

    Hi @lerq

    The easiest way is to edit the code WIHIN your loop. This could would normaly display the title, link, excerpt for the post.

    Just add some logic that compares the date value to today. Something like this:

    
    <?php 
    
    $today = date('Ymd');
    $expire = get_field('expire');
    
    if( $expire < $today )
    {
    	// skip this loop
    	continue;	
    }
    
    ?>
    

    Thanks
    E

    • lerq

    • December 19, 2013 at 6:25 am

    Brilliant – thank you Elliot!

    Loads simpler than anything else that I’ve seen!

    • pagol

    • May 13, 2018 at 8:16 pm

    Can you help me for write query for me. bellow is my code. i want hide or make it draft.

    <?php query_posts($query_string); ?>
                    <?php while ( have_posts() ) : the_post(); ?>
                    <li>
                        <h2><?php the_title(); ?></h2>
                        <h5> <?php the_field('expire'); ?></h5>
                        <a href="<?php the_permalink() ?>">Details</a>
                    </li>
                    <?php endwhile; 
    ?>
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.