Out of the box, WordPress provides tons of functions that can be used to interact with the database. In most cases, the WP_Query class and related functions such as wp_insert_post, update_post_meta, get_posts will be sufficient to get the job done. However, there will be times that we’re required to do something that is not provided by WordPress natively, especially when we need to deal with custom tables. In this tutorial, we’ll walk through the most important class to deal with databases in WordPress – wpdb, including a few tips and tricks that can be implemented in our development workflow later on. We’ll also touch on dbDelta that can be used to create custom tables in our plugin. Working with the wpdb Class wpdb is perhaps the single most important class that we use when we need to deal with database directly. It is based on the ezSQL class written by Justin Vincent, adapted to work with WordPress. The basic methods and properties of the wpdb class is already well explained on the WordPress Codex page so there’s no point to reiterate them here. Instead, we’re going to go through a few common mistakes that WordPress developers can make, how to rectify them, as well as best practices
Share This