Reading real WP data: users, options, and posts
WPDB – Reading Real WordPress Data: users, options, and posts
Up to now, you were mostly using the users table as a safe practice target. This lesson is about understanding what kind of data actually lives in the main WordPress tables, so your queries start feeling tied to the real app instead of random SQL practice.
The big idea is this: WordPress stores different kinds of information in different tables, and each table has its own purpose.
The users table stores the core identity data for each user. Things like ID, login, email, display name, registration date, and password hash live there. Extra user-related data is commonly stored separately in usermeta.
The options table stores site-level settings. This is the database layer behind the Options API. In real plugin development, you will often read and write settings through functions like get_option() instead of querying the options table directly, but reading it with $wpdb is still useful for learning what is actually stored there.
The posts table is broader than the word “posts” makes it sound. It stores normal blog posts, pages, attachments, revisions, and other content types. The post_type column is what helps distinguish what kind of content each row represents.
So the mental model for today is:
- users table = core user identity data
- options table = site and plugin settings
- posts table = content objects of many types
One more useful mindset point: just because you can read something with $wpdb does not always mean that is the normal WordPress way to work with it. For example, users are often accessed through get_userdata(), options through get_option(), and posts through get_posts() or WP_Query.
For now, though, we are staying at the database-reading level on purpose, because it helps you understand what WordPress is doing underneath.
References:
- wpdb class: https://developer.wordpress.org/reference/classes/wpdb/
- users data overview: https://developer.wordpress.org/plugins/users/working-with-user-metadata/
- Options API handbook: https://developer.wordpress.org/apis/options/
- get_option(): https://developer.wordpress.org/reference/functions/get_option/
- default post types: https://developer.wordpress.org/themes/classic-themes/basics/post-types/
- get_posts(): https://developer.wordpress.org/reference/functions/get_posts/