I have used

add_filter( 'posts_where', array(&$this, 'new_filter_where' ));
function edcal_new_filter_where($where = '') {
        global $wpdb;
        $where .= " AND (($wpdb->postmeta.meta_key = 'assignto' AND $wpdb->postmeta.meta_value = '7')) ";            
        return where;

now how to print sql query that fired by my filter?

1 Answer 1


The quick and dirty way is to put var_dump($wp_query->request) (or whatever you've named the WP_Query object if you've created a new one) on the page the query runs on and after it runs.

You can also add define('SAVEQUERIES', true); to wp-config.php to save the queries for analysis. You can read the queries something like this from the Codex:

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    echo "</pre>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.