Setting expiration options programmatically
-
So post expirator is working great for me, but I’ve got one issue. I’m creating a certain category of posts programmatically and want to set them to expire after five days. To do that, I’m using this code when I create the post:
$current_time = date(U); $expire_time = $current_time + 432000; // 5 days is 432000 seconds update_post_meta($post_id, '_expiration-date', (string)$expire_time); update_post_meta($post_id, '_expiration-date-options', 'a:2:{s:10:"expireType";s:6:"delete";s:2:"id";i:'.$post_id.';}'); update_post_meta($post_id, '_expiration-date-status', 'saved');
If you look at the resulting post in the dashboard, you’d see that post expirator is turned on (it’s turned off by default) and the post expiration date is just as intended. But the post is set to expire to a draft, not to the trash, as it’s supposed to. And ultimately, it never does expire, to a draft OR to the trash. (I tested this by setting the expiration date to a few minutes in the future instead of five days.)
Any idea what I’m doing wrong here?
- The topic ‘Setting expiration options programmatically’ is closed to new replies.