Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Delete Expired Jobs
<?php
/**
* @package Delete Expired Jobs
* @version 0.0.1
* @see http://opentuteplus.com/delete-expired-jobs-locomotive/
*/
/*
Plugin Name: Delete Expired Jobs
Plugin URI: https://shop.opentuteplus.com
Description: Delete Expired Jobs
Version: 0.0.1
Author URI: http://iamkisho.re
*/
function find_expired_jobs() {
register_batch_process( array(
'name' => 'Delete Expired Jobs',
'type' => 'post',
'args' => array(
'post_type' => 'job_listing',
'post_status' => 'expired'
),
'callback' => 'delete_expired_jobs', // callback function
) );
}
add_action( 'locomotive_init', 'find_expired_jobs' );
function delete_expired_jobs( $post ) {
$media = get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment'
));
if (!empty($media)) {
foreach ($media as $file) {
wp_delete_attachment($file->ID); // @todo need to check if media file is not attached to other post.
}
}
wp_delete_post( $post->ID, true );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment