Deleting old expired jobs

Note: All code examples on this site are provided for developer reference/guidance only and we cannot guarantee that they will always work as expected. Our support policy does not include assistance with modifying or debugging code from any code examples, and they may be changed or removed if we find they no longer work due to changes in our plugins.

 

Note: this snippet works by moving expired jobs to the trash.  Once in the trash, WordPress takes over, and deletes trash by default after 30 days.   This snippet does not automatically,  upon expiration,  delete expired jobs.

Unlike old ‘previews’, expired jobs are not deleted by default. But you can enable this functionality using a quick snippet in your theme’s functions.php file (or using a functionality plugin):

If enabled, expired job listings will be deleted after “job_manager_delete_expired_jobs_days” days which defaults to 30. Cleanup will be done daily via a cron job.

If you’d like to change the default 30 days setting, the Trash status page on WordPress.org provides some solutions.