how does $wpdb differ to WP_Query?

I’m going to write a function to return the next/prev post in a specific category. can anyone tell me what the differences would be in using $wpdb as opposed to WP_Query(); eg new WP_Query(args)? what determines which of these should be used?

cheers,
Gregory

3 s
3

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.

Leave a Comment