This is the ideal method where we create our own query logger and specify which queries we need to track. Let's look at the implementation of this method using the following code:
function wpc_filter_query( $query ) { if (strpos($query, 'INSERT') !== false || strpos($query, 'UPDATE') !== false || strpos($query, 'DELETE') !== false) error_log('#### $query', 0); return $query;};add_filter( ‘query', ‘wpc_filter_query', 10, 1 );
The preceding code uses WordPress query filter to filter all the queries that are executed in user request. A complete sql query is parsed as a parameter and we filter INSERT, UPDATE, and DELETE queries. Then, we can log the queries to a preferred file. Here, we are adding the queries to ...