No one has figured out the custom field for “How to Expire”: ‘Delete’?
What is your desired functionality for such a feature?
Hi Aaron,
Thanks for getting back on the support forum. I noticed you updated the plugin. I am having an issue though. I import using the custom fields of “_expiration-date-status > saved” and “_expiration-date > 1496112420”. So it imports properly but it won’t actually delete/draft after the expiration time. This seems to be a problem with the cron which is what people seem to say. How to fix this? Thanks
You can’t just add the meta data – that does not actually set the cron events. With your import process, you’ll need to run the “_scheduleExpiratorEvent($id,$ts,$opts)” function which will solve your problem.
You will need to manually build the “opts” array – easiest way may be to just copy it from a different post for what you want, and then just update the post id.
Hope that helps.
Sorry I am not very skilled with this stuff. How do I run the “_scheduleExpiratorEvent($id,$ts,$opts)” or build the “opts” array?
In another post someone seemed to get this code working with WP All Import plugin:
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($id) {
$expiration_date = get_post_meta($id, 'expiration-date', true);
if ($expiration_date) {
$opts = array();
$opts['expireType'] = 'delete';
$opts['id'] = $id;
echo "Setting expiration date for post " . $id . " to the timestamp " . $expiration_date;
_scheduleExpiratorEvent( $id, $expiration_date, $opts );
} else {
echo "No expiration date set for post " . $id . ". Exiting";
}
}
The problem is add_action('pmxi_saved_post', 'post_saved', 10, 1); is part of WP All Import and I am using Woocommerce CSV Importer. Is it possible to get this to work without that part? Let me know. Thanks
-
This reply was modified 8 years, 11 months ago by
crowds90.
Wherever you are trying to currently update the meta, just replace that code with a variation of this:
$expiration_date = get_post_meta($id, '_expiration-date', true);
if ($expiration_date) {
$opts = array();
$opts['expireType'] = 'delete';
$opts['id'] = $id;
echo "Setting expiration date for post " . $id . " to the timestamp " . $expiration_date;
_scheduleExpiratorEvent( $id, $expiration_date, $opts );
} else {
echo "No expiration date set for post " . $id . ". Exiting";
}