The wpdb
class is the interface with the database. WP_Query
uses wpdb
to query the database. You should use WP_Query
when dealing with the native WordPress tables, to integrate your code properly with the WordPress environment. Use wpdb
directly when you need to access data in your own tables.