When using Action Scheduler to schedule processing the tasks, the completed tasks are stored for 30 days in your database by default. You might want to remove the action scheduler completed tasks a little earlier or instantly after completion. The following code snippets can be used for this purpose.

function sa_as_retention_period() {
	return DAY_IN_SECONDS;
}
add_filter( 'action_scheduler_retention_period', 'sa_as_retention_period' );

With the above code snippet, the completed tasks are automatically removed in a day instead of 30 days. In case it helps, here’s how to easily add PHP code snippets to your WordPress site.

Here are other values you can use in the function above.

  • MINUTE_IN_SECONDS
  • HOUR_IN_SECONDS
  • DAY_IN_SECONDS
  • WEEK_IN_SECONDS

I hope it’s helpful!

Remove Action Scheduler Completed Tasks
Tagged on:

Sanjeev Aryal

Don't bury your thoughts, put your vision into reality ~ Bob Marley.

Leave a Reply

Your email address will not be published. Required fields are marked *

× WhatsApp