Usually, when we think of content inside WordPress, we think of posts and pages, but in fact, posts and pages are just the two post types that WordPress has by default. In many real-world applications, having only these two content types is not enough. Understanding content types and how they interact with each other can help us understand WordPress more deeply so that we can write more advanced content queries when developing themes and plugins.
The Main Types of Content in WordPress
In WordPress, there are 4 main content types and they are:
- writings
- commentaries
- subscribers
- link (on a website)
Of these, links are the content type that has been abandoned, so we only need to understand the first three content types.
writings
The article is WordPress DatabaseThe most important type of content in this can be confusing because the wp_posts
Data tables are used to describe a lot of content (articles, pages, custom article types, etc.), and there is an article type called "article" in the default article type. Adding the following parameter to the query may seem redundant, but it is indeed correct.
'post_type' => 'post'
WordPress has the following post types by default:
- writings
- web page
- attachment (email)
- releases
- Navigation menu items
Like I've done in this series of articles. WordPress Database RelationshipsAs mentioned in the article, the article can establish a connection with itself, and whether to support this kind of link in the background interface, you need to support it when you create a new article type, the default support for this kind of connection relationship is the page, you just need to specify the parent page when you create a new page.
WordPress developers may be familiar with the first three post types and unfamiliar with the last two, with each post version saved in the wp_posts
The parent article of the version in the datasheet is the article itself. The navigation menu items are saved as articles and displayed with their own spinning functions.
We can add article types as needed. The added article types are similar in presentation to the default articles and pages, whether they are similar to articles or pages depends on the parameters we use when creating the article types.
The chart below shows thewp_posts
data table and its association with other data.
commentaries
Comments are stored in his own data table wp_comments
This is a bit like the article data table, where comment data can be passed through the wp_commentmeta
Datasheets append additional data, but they are different content types and require different fields.
Comments will be connected to the article through a one-to-many relationship, and they are also connected to the article through the comment_parent
field is connected to itself, this is to distinguish whether a comment is a top comment or a reply to another comment. If the user is logged in, the comment data is also linked to the wp_users
The data table establishes a connection to discern who made the comment.
The chart below shows the wp_comments
Table and his relationship.
subscribers
users have their own data sheets. wp_users
respond in singing wp_usermeta
A metadata table, at a glance, looks like a user and a content type different from an article, but on closer consideration, users and articles are actually pretty much the same, and like articles, users can be queried and output a user archive, which they contain user profile data. There is a big difference between the data structure of a user article type and that of an article or comment, so it makes more sense to use a separate user data table to store the user's data.
The following diagram shows the user data table and how it relates to other data.
Metadata for content types
In addition to the deprecated links, three of the four content types above have their own Metadata for the article type.
- Article: post_meta
- Comment: comment_meta
- User: user_meta
I'll take the time to write a post about Metadata for content types, detailing what the various Metadata's do and how to use them.
summarize
In summary, WordPress stores data using different types of content types and relationships between those types, not just posts and pages, but also custom post types, media, versions and menu items.
Understanding the individual post types, figuring out how they work, and being able to understand the similarities and differences between them can help us develop more powerful themes and plugins.