Title: Problem using &#8220;query&#8221; filter
Last modified: August 18, 2016

---

# Problem using “query” filter

 *  Resolved [ketsugi](https://wordpress.org/support/users/ketsugi/)
 * (@ketsugi)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/)
 * I’m trying to write a plugin that’ll log every SQL query WP sends (for troubleshooting
   purposes). Looking at the query() function in wp-includes/wp-db.php in trunk 
   seems to show that all SQL queries are run through the “query” filter.
 * So I added a function in my plugin called log_query(), and added this line in
   my plugin:
 * `add_filter('query', array('Developer', 'log_query'));`
 * However, this line causes WP to die for an unknown reason. Changing the filter
   name to any other known filter lets the PHP code run, but of course that doesn’t
   do what I want it to do. Is there any reason why this “query” filter doesn’t 
   seem to be working?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/#post-498903)
 * What’s with the array? That doesn’t make much sense.
 * Try `add_filter('query','log_query');` instead. You’ll then need your function
   to look like this:
 * `function log_query($query) {
    // do stuff with $query return $query; }
 *  Thread Starter [ketsugi](https://wordpress.org/support/users/ketsugi/)
 * (@ketsugi)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/#post-498905)
 * The array is when all the plugin’s functions are enclosed in a class (for namespacing
   purposes), where “Developer” is the name of the class. This isn’t the issue; 
   it works in all the other add_action and add_filter calls. As I said, the problem
   is the “query” filter name.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/#post-498909)
 * Hmmm… Is your function actually returning the $query? A filter is expected to
   modify text and return it. If you fail to return it, then you’re wiping out the
   query in the process.
 *  Thread Starter [ketsugi](https://wordpress.org/support/users/ketsugi/)
 * (@ketsugi)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/#post-498910)
 * Otto42: that was the problem. Thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problem using “query” filter’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * 4 replies
 * 2 participants
 * Last reply from: [ketsugi](https://wordpress.org/support/users/ketsugi/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/problem-using-query-filter/#post-498910)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
