How To Run Safe Database Queries In WordPress With $Wpdb The global $wpdb object lets you query the WordPress database directly. Use it when the standard functions are not enough, and always use $wpdb->prepare() to protect against SQL injection.