Is there a way to hook into the WPDB instance ($wpdb)?

What i basically want, is to execute a own function BEFORE the desired query get’s executed.

Is this possible?

Additional question for comment to first answer:

    $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "test WHERE type = %s and ip = %s", $type, $ip_full_log);
    $fetch = $wpdb->get_results($query, ARRAY_A);

Would this parse the final query to my callback function?

1 Answer
1

query – you will get sql as argument of the callback.

add_filter('query', 'some_callback_that_change_query');

function some_callback_that_change_query($sql){
    remove_filter('query', 'some_callback_that_change_query');
    // your banny wrote
    add_filter('query', 'some_callback_that_change_query');
    return $sql;
}

Leave a Reply

Your email address will not be published. Required fields are marked *