WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Understanding pages in the database (3 posts)

  1. shastaw
    Member
    Posted 4 years ago #

    Several times I have realized I don't really understand how pages work differently than posts wrt. the underlying database. Today this was driven home when I updated my database tables to not use wp_ as the default prefix. Everything went smoothly -- except all of my pages lost their assigned templates. I poked about through the database a bit, but realized I don't understand how pages are stored differently from posts well enough to fix things quickly. I wound up re-assigning each page's template, but would like to understand why I had to do this as I suspect it will come up again in some context.

  2. Samuel B
    moderator
    Posted 4 years ago #

    They really aren't any different wrt the database. They are both stored in the _posts table.
    Go to phpmyadmin and "browse" the _posts table
    under the heading "post_type", you will see them distinguished by post or page
    you should also be able to see the assigned template for the page(s)

  3. shastaw
    Member
    Posted 4 years ago #

    Ok, after poking around in the database, here is what I learned.

    Pages' templates are not stored in the _post table, they're in the _postmeta table. When I changed my tables to have a prefix other than wp_ , all the pages I had assigned templates to lost them.

    I changed my tables by backing up, then using a text editor to search and replace the wp_ prefix to mine, let's call it new, then dumping the old tables and importing the altered database. It turns out that the required metakey is _wp_page_template, and by my search and replace I turned it into an unrecognized key, as you can see in these before and after snapshots of the database :

    After the update, before I fix the page :

    Edit 	Delete 	153 	99 	_edit_last 	2
    Edit 	Delete 	152 	99 	_edit_lock 	1277486519
    Edit 	Delete 	154 	99 	_new_page_template 	testpage.php

    When I look in the WordPress interface for page 99, I see "default template" listed. Once I change it manually in the interface to the template it should be I get this :

    Edit 	Delete 	153 	99 	_edit_last 	3
    Edit 	Delete 	152 	99 	_edit_lock 	1277486663
    Edit 	Delete 	154 	99 	_new_page_template 	testpage.php
    Edit 	Delete 	238 	99 	_wp_page_template 	testpage.php

    So, the solution is to either exclude the contents of the _metapost table when searching and replacing, or to patch it up afterward.

    Now, however, I'm concerned that there might be other places in the database where I haven't yet noticed something broken. I found lots of tutorials online stating that one should update the wp prefix either through search and replace, or manually, to secure a site.

    Can anyone provide a link to a more robust approach, and/or to a list of places we should NOT update the wp_ prefix in the database?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic