Where Does WordPress Store Pages

Many wonder where are all the posts and pages stored on WordPress, where does WordPress store pages and how does WordPress access them?

The WordPress database is a place where all the posts and pages are stored. This is an important step of how the site for WordPress works. Without this database, none of the posts and pages will be stored, and when a user visits your WordPress site, none of these posts and pages will show up.

In this article, you will learn more about WordPress, the working of the WordPress database, and by using the database, how they design a page making it convenient when a user visits your WordPress site.

How does WordPress work – Where does it WordPress Store Pages i.e. Files and Data

WordPress is CMS (Content Management System). It doesn’t create a static HTML file. Instead, all the information on your pages is stored in the database. Every time you load a WordPress page, it utilizes codes to access the information.

WordPress has two additional elements

* When the website is set up, WordPress runs on the core files.

* Files uploaded to the WordPress website include media attachment, plugin files and theme files.

The pages on your WordPress site are designed by WordPress, using all this information and save you the hassle of writing codes.

Let’s dig deeper and see where your posts and pages are saved. Let’s also look at the structure of the WordPress database.

Storage of WordPress Pages and Posts

The WordPress database stores all the information that’s on your WordPress site. They are as follows:

* Posts, Custom posts and all your pages. For example, Details of all the clothes listed (if you’re an owner of a clothing line).

* All the information of every attachment.

* Any metadata like tags and categories of posts (if your website has any taxonomies), through plugins, any metadata and custom fields.

* All the data on your attachment that’s uploaded to the website, including the file name, description and metadata like alt text and the data to which the posts and pages are attached.

* Your settings that include site settings like description, site title and detailed specifics of your setting for the theme and plugins.

* Settings and user data.

Database Tables

The database of WordPress has 12 tables. 

Most of these database tables are linked to one another. wp_posts is the most important of all.

wp_posts: wp_posts is a place where all your WordPress pages and posts are stored. This table stores all the data on the attachment. It also has revisions and navigation menus.

wp_postmeta: wp_postmeta is linked to wp_posts. It also saves metadata of all the WordPress pages and posts.

wp_comments: wp_comments is linked to wp_users. It saves all the comments of your posts; it includes all the details of the person that posted the comments and the time/date/day/ etc. of the post.

wp_commentmeta: wp_commentmeta is linked to wp_comment. It saves every metadata of every comment.

wp_terms: wp_terms is linked to wp_terms_taxonomy. Every taxonomy term on your website is saved here, which includes tags and categories.

wp_term_taxonomy: wp_term_taxonomy is linked to wp_terms_relationships and wp_terms. The wp_terms table stores all the taxonomy for every term.

wp_term_relationship: wp_term_relationship is linked to wp_posts and  wp_term_taxonomy. The taxonomy terms assigned is linked to your posts.

wp_termmeta: wp_termmeta is linked to wp_terms. The taxonomy terms have some metadata. This metadata is stored here.

wp_users: wp_users are linked to wp_comments and wp_posts. Your website has a list of users along with their password, username and other information. All this information is stored here.

wp_usermeta:wp_usermeta is linked to wp_users. Your users have metadata; this metadata is stored by it.

All the data is linked due to the relationship among the tables. It makes sure that WordPress knows the taxonomy terms for a particular post, like the person who wrote it, the comments, and much more.

There are two tables that are not linked with the others, and your posts don’t have a relationship with them:

* wp_options: wp_options saves settings and global options for the entire website. A post will be saved in wp_postmeta, so it isn’t for posts.

* wp_links: wp_links saves all the information of the blogroll, similar to the blogging that used to happen in the initial days. It’s a record of links, and it is not commonly used today.

So, your WordPress pages and posts are saved in wp_posts. However, another table that is linked to them has all the metadata stored.

You might be wondering how all this data is interpreted by WordPress and converted to pages on your website?

WordPress uses ‘The Loop’. The loop uses a very specific code that collects database content and displays it on your website pages. This is applicable for individual pages, home pages, search pages, and archive pages. You will find many videos that will give you a short synopsis on the loop. We advise you to take a look at them.

Loops

The loop starts with the code mentioned below:

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>

There might be posts that need to be displayed on your website. This examines and keeps an eye out for such posts. the_post() template tag is used to display the page content on your web page.

Here ‘post’ is not your blog post; post means content to post that includes custom post, attachments and post page. It can get tricky to understand!

At the end you will find the code that mentioned below:

<?php endwhile; endif; ?>

The looping is stopped through post by WordPress once it receives all the information for the pages on your website. Then if the check is closed and it stops scrutinizing for posts. The code that displays page content is displayed between the two lines. We will take a quick peek at the various content types soon.

Depending on the page being visited by your visitors, WordPress makes available relevant content. It is aware of the type of archive for an archive page, like the category of the archive. Whereas for an individual page or post, it is aware of the page and post being displayed. It uses a valid template file from the theme hierarchy to display the correct loop for the present content file.

Let’s look at this action.

Pages and Single Posts: The loops for individual posts and pages will only run once because the content for these individual posts and pages need to be displayed. WordPress will fetch only the relevant page and post as it is aware of it.  An example of a loop for an individual loop will look as follows:-

<?PHP if( have_posts() ) : while( have_posts() ) : the_post(); ?>

    <article id=”post-<?php the_ID(); ?>”<?php post_class(); ?>>

        <h1 class=”entry-title”><?php the_title(); ?></h1>

        <section class=”entry-meta”>

            <?php the_date(); ?>

        </section><!– .entry-meta –>

        <section class=”entry-content”>

            <?php the_content(); ?>

        </section><!– .entry-content –>

    </article><!– #post-## –>

<?php endwhile; endif; // end of the loop. ?>

It is a straightforward version of the loop. Some theme includes metadata; it is a record of comments and categories. It reveals the core content of the page and post in the output. The article element has everything enclosed in it with IDs and classes that are set with the help of the template tag –  post_class(). Access to the database helps it to get all this done automatically.

Archive Pages: Loop is also used by archive pages; they fetch and display various posts instead of just a single post. For example, all the post from the category archive will be outputted. On the basis of the display of the page, WordPress will work accordingly. When the posts are displayed, WordPress keeps running through the loop over and over again, making the while () part more obvious.

Below you will see an example for the category archive:-

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25<?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?>   <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>     <h3 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( esc_attr__( ‘Permalink to %s’, ‘compass’ ),  the_title_attribute( ‘echo=0’ ) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h3>           <?php if ( has_post_thumbnail() ) { ?>                <a href=”<?php the_permalink(); ?>”>             <?php the_post_thumbnail( ‘medium’, array(                 ‘class’ => ‘left’,                 ‘alt’   => get_the_title()                 ) );             ?>         </a>     <?php } ?>       <section class=”entry-meta”>         <?php the_date(); ?>     </section><!– .entry-meta –>       <section class=”entry-summary”>         <?php the_excerpt(); ?>     </section><!– .entry-content –> </article>   <?php endwhile; endif; ?>

Data Backup

The vital component of excellent WordPress Security is ensuring regular backups. Backing up your data is very important, especially if you are planning to make some changes to your WordPress.

Ideally, there is a backup solution for all the data of your entire website; however, through your phpMyAdmin, you can export the WordPress database.

Now, simply follow the prompts to export the file. In case anything goes wrong, you can use the import tab and restore the backup.

Where can you find the WordPress Post Templates and Theme Pages

WordPress saves the metadata and contents of all your WordPress pages and post in a database. This data is merged with the present theme’s PHP template. You can easily locate it in the file system. In order to access these files on your website, you can use cPanel file manager or FTP like FileZilla.

Conclusion:

The wp_post tables of the database save all the content of your WordPress pages and posts. The templates of the WordPress pages and posts are saved and can be retrieved from /wp-content/themes/your-themes/. There is no requirement to make any changes to the pages and posts of the database.

The WordPress dashboard does an excellent job. While editing specific metadata from the admin area of WordPress, if you come across any challenges, approaching the database directly can be a definite fix. You can also check our article on What is the Difference Between VPS Hosting and a Dedicated Server.

Leave a Comment