Support

Account

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

Solved

Using date picker to set post expiry date

  • 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

  • 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

  • Brilliant – thank you Elliot!

    Loads simpler than anything else that I’ve seen!

  • 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)

The topic ‘Using date picker to set post expiry date’ is closed to new replies.