Product successfully added to your shopping cart.

View Categories

What is the $wpdb variable in WordPress, and how can you use it to improve the following code?

< 1 min read

Table of Contents

Using the $wpdb global object

WordPress provides a global object, $wpdb, which is an instantiation of the wpdb class. By default, $wpdb is instantiated to talk to the WordPress database.

The recommended way to access $wpdb in your WordPress PHP code is to declare $wpdb as a global variable using the global keyword, like this: