Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

FatLabllc on "Getting delete query to work in wp-cron"

$
0
0

I have been struggling with this for a little while now and hoping someone can provide some advice.

I am writing a plugin that includes a wp-cron job to delete records from a table after they are 24 hours old. The cron job is created just fine on activation and using several cron related plugins I can see and execute the cron job without issue. However the table rows meeting the 24 hour criteria are not deleted. My code is below.

Thanks so much for any insight!

register_activation_hook( __FILE__, 'sap_create_schedule' );

	function sap_create_schedule() {
		wp_schedule_event( time(), 'hourly', 'sap_hourly_cleanup' );
	}

	add_action( 'sap_hourly_cleanup', 'sap_cleanup' );

	function sap_cleanup() {
	$table_name = $wpdb->prefix . "sap";
	$wpdb->query("DELETE FROM $table_name WHERE creation_time >= now() + INTERVAL 1 DAY");
	}

Viewing all articles
Browse latest Browse all 8245

Trending Articles