Comment on page
There are multiple data types in WordPress, but the basic data types stored in the database are:
- Site Options
Some of these data types can have additional data attached to them in the form of meta data, some of them have types and statuses.
There are also roles and capabilities, which are not considered content and apply exclusively to users.
Meta data is data with a key/name and a value, attached to another piece of data. Some people will know them as custom fields. Others will know them as user meta.
Post Meta ( or Custom fields ) are normally shown in the post edit screen, but if the post meta's key/name begins with an underscore, that field is hidden. This way features such as featured images can be built with their own user interfaces.
Posts, pages, attachments, and menus are all different kinds of posts. You can also register your own post types, and these are referred to as custom post types. Remember to flush permalinks (manually: Dashboard > Settings > Permalinks > Save Changes or programmatically via flush_rewrite_rules) if you modify or add a post type. If you do not do this, some links will generate 404 errors.
*Warning: Developers sometimes attempt to work around the rewrite rules by flushing rewrite rules on the
initaction using the
flush_rewrite_rules, but this is a mistake. It can lead to unexpected behaviours, and has a large negative performance impact. Rewrite rules are expensive to build.
The default post types are as follows:
- Post (
- Page (
- Attachment (
- Revision (
- Navigation menu (
Menu items are stored as
nav_menu_itemposts, however, the menu itself is a term in a custom taxonomy that contains
A post of type
revision, revisions are historical copies of posts, and are tied to their original post via the post_parent field. To get a posts revisions, grab all its children of type
revision. If a database is growing very large or a particular post/page is frequently/automatically edited, you can limit the number of revisions stored.
When you upload a file, WordPress does not reference the image or file using its URL, it uses an attachment. Attachments are posts of type
attachment, and are referred to by their post ID. For example, when you set a featured image on a post, it stores your chosen image's post ID in that post's meta (
If a file is uploaded whilst editing a post (rather than in the Media Library itself), it's
post_parentfield is set to that of the post.
WordPress generates and saves resized versions of the original at the time of upload for better performance. They can be cropped and manipulated independently and the dimensions and filenames are stored in the attachment postmeta.
The default image sizes are configured in Dashboard > Settings > Media. If you need more, you can use add_image_size and also control cropping. You can request a specific size of image using the attachment ID and the image size name (e.g. 'medium', 'large'.)
Comments have their own table, and are attached to a post. Comments are not a type of post however, but they are capable of storing meta data. This is rarely used by developers but allows for interesting things.
A taxonomy is a way of categorising or organising things. Items are organised using terms in that taxonomy.
For example, yellow is a term in the colour taxonomy. Big and small are both terms in the size taxonomy.
The Tags and categories that come with WordPress are both taxonomies. Individual tags and categories are called terms.
Taxonomy terms are tied to Object IDs, where an object ID can be any kind of data. This includes posts, users, or comments. These IDs are normally post IDs, but this is purely convention. There is nothing preventing a user or a comment taxonomy. A user taxonomy would be useful for grouping users into locations or job roles.
Options are stored as key value pairs in their own table. Some options have an autoload flag set and are loaded on every page load to reduce the number of queries.
Transients are stored as options and are used to cache things temporarily
Here's a table showing the full spectrum of data types in WordPress that are stored in the database: