Hiding pages and posts until date

Hi, I am looking for a way to make pages or posts disapear, become private or deleted on a planned date. WordPress can plan a page to be visible on a future date and time, but there is no way to remove/hide it.

I have read this article https://premium.wpmudev.org/blog/wordpress-time-date-plugins/ where I only find plugins where you can hide or display some content on the page, at specific times, this is really cool, but not what I'm looking for.

I found a plugin called "Post expirator" https://wordpress.org/plugins/post-expirator/ it is supposed to do just that, make a page private or deleted at a selected future date. But it's not working, the page is not being removed, I have tested it many times, it just doesn't disapear.

You write that you help with any wordpress issues, and I am hoping you can help me find a solution to this problem, where we need to launch pages, and automatically hide them in the future.

We are thankful for the plugins to hide and show page content.

Thanks
Lykke

  • Michelle Shull

    Hi, Lykke!

    I've done some searching, and it appears the plugin you're using has been abandoned. It's a shame, too, because the first ten pages or so of Google links are all tutorials saying to use this plugin. And all those tutorials have comments saying the plugin doesn't work. Hmm.

    I found this, which is a function you'd drop in functions.php, but it doesn't have a date stamp I can see. http://coderrr.com/wordpress-post-expiration/

    function is_post_expired($post_ID = null){
    
        if(!$post_ID) global $post;
    
        $post_ID = $post_ID ? $post_ID : $post->ID;
    
        //Human Friendly Expiration Date
        $expiration = get_post_meta($post_ID, 'expiration', true);
    
        //Adjust server time for your timezone
        date_default_timezone_set('American/New_York');
    
        $expiration_timestamp = strtotime($expiration);
        $time_left = $expiration_timestamp - time();
    
        if($time_left < 0):
            if(expire_post($post_ID))
                return true;
        endif;
    
    }
    
    function expire_post($post_ID){
    
        $args = array(
            'ID' => $post_ID,
            'post_status' => 'draft'
        );
        if(wp_update_post($args))
            return true;
    }

    This needs a custom field called "expiration" on your add new post page. This function converts the human-readable time to Unix (computer readable) time, and changes the post status to draft after the expiration date has passed.

    Are you comfortable dropping new code into your functions.php?

    Thanks for your question, hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.