Thanks to everyone who takes a look. I've spent countless hours trying to make this work, but no matter what I tried it still doesn't work. Hopefully I'm missing something simple, but I'm stuck...
Here's my code on the submit page where I add a new page and a cron job to delete it in the future:
$seconds = time() + $_POST["days"] * 86400;
wp_schedule_single_event($seconds, 'crondelete', $new_post_id );
And here's the relevant code in functions.php:
add_action( 'crondelete', 'delete_page_in');
function delete_page_in($args) {
wp_delete_post($args);
}
The cron part is working properly:
But it looks like the parameter isn't passed to the function, so once I run the cron job- nothing happens(the page won't delete).
Thanks to everyone who takes a look. I've spent countless hours trying to make this work, but no matter what I tried it still doesn't work. Hopefully I'm missing something simple, but I'm stuck...
Here's my code on the submit page where I add a new page and a cron job to delete it in the future:
$seconds = time() + $_POST["days"] * 86400;
wp_schedule_single_event($seconds, 'crondelete', $new_post_id );
And here's the relevant code in functions.php:
add_action( 'crondelete', 'delete_page_in');
function delete_page_in($args) {
wp_delete_post($args);
}
The cron part is working properly:
But it looks like the parameter isn't passed to the function, so once I run the cron job- nothing happens(the page won't delete).
Share Improve this question asked Aug 22, 2019 at 19:45 StefanRStefanR 133 bronze badges 2- The third parameter should be an array of arguments - check this example. – Sally CJ Commented Aug 22, 2019 at 22:29
- 1 Thank you Sally, I've checked the answer from below first, but it's essentially the same issue as you pointed out. – StefanR Commented Aug 23, 2019 at 7:45
1 Answer
Reset to default 0Comparing your code to the Wordpress function wp_schedule_single_event, it appears you failed to indicate that parameters would be passed.
Perhaps the following version of your code will work for you.
add_action( 'crondelete', 'delete_page_in',10,1);
wp_schedule_single_event($seconds, 'crondelete', array($new_post_id ));
Notice the add_action now includes two extra parameters: 10=Priority, and 1=Accepted Arguments to be passed.