Search for answers or browse our knowledge base.
Deleting specific events from the activity log (database)
In some instances, you may wish to remove all traces of specific events with a specific ID from your records. The process itself is simple and can be done with the code provided below. Let’s take a look at the code and how it works.
How WP Activity Log event data is stored
You may be tempted to think all events are just loaded into one database table. That’s not the case. To keep things quick and efficient, the activity log data is stored in two tables. For details on this refer to WP Activity Log plugin & activity log database documentation.
How to delete events with a specific event ID from the activity log
Using a SQL query
With this in mind, this means when removing all event data you would need to remove it from two tables. To do this, simply run the below query on your WordPress database.
DELETE FROM wp_wsal_metadata WHERE wp_wsal_metadata.occurrence_id IN (SELECT id FROM wp_wsal_occurrences WHERE alert_id = 2001); DELETE FROM wp_wsal_occurrences WHERE alert_id = 2001
Simply change the alert_ID 2001 to the ID of your choice. Refer to the complete list of activity log event IDs for more information on what each event ID represents.
Using code snippet
If you are not familiar with running MySQL queries, instead you can add the below code snippet to your functions.php and refresh the page. Once you refresh the page, the code is executed and you can remove the code again.
global $wpdb; $wpdb->query( "DELETE FROM wp_wsal_metadata WHERE wp_wsal_metadata.occurrence_id IN (SELECT id FROM wp_wsal_occurrences WHERE alert_id = 2001); DELETE FROM wp_wsal_occurrences WHERE alert_id = 2001" );
Simply change the alert_ID 2001 to the ID of your choice. Refer to the complete list of activity log event IDs for more information on what each event ID represents.