I'm looking for a way to automatically purge the database of _wp_session
records in WordPress.
The SQL query I have is:
DELETE
FROM `wp_options`
WHERE option_name LIKE '_wp_session%'
I would like to know how I can run it once per day with a plugin, PHP script or cron job.
Thanks!
You should schedule an event that occurs daily. You can do this for example in a custom plugin.
register_activation_hook(__FILE__, 'my_activation');
add_action('my_daily_event', 'do_this_daily');
function my_activation() {
wp_schedule_event(time(), 'daily', 'my_daily_event');
}
function do_this_daily() {
$wpdb->query(
"DELETE FROM $wpdb->options
WHERE option_name LIKE '_wp_session%'
"
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With