Skip to content
- Official WordPress Common APIs Handbook, Database API.
- Syed Balkhi and Editorial Staff. Beginner’s Guide to WordPress Database Management with phpMyAdmin. WP Beginner, 2014.
- Title is somewhat misleading. This article covers the default database table structure AND how to use phpMyAdmin to cover it.
- Kevin Muldoon. Optimizing Your WordPress Database – A Complete Guide. wpmudev, 2019.
- Jack Kitterhing. MySQL and WordPress: Understanding How Databases Work. wpmudev, 2017.
- Daniel Pataki. The Developers Guide to the WordPress Database (and Writing Better Code). wpmudev, 2015.
- Iain Poulson. Tour of the WordPress Database. Delicious Brains, 2015.
- Shaumik Daityari. The WordPress Database Demystified. sitepoint, 2014.
- Josh Pollock. Why WordPress Projects Need a Proper Database Abstraction. Torque, 2016.
- Firdaus Zahari. Working with Databases in WordPress. sitepoint, 2016.
- Andy Adams. Finding and Fixing Slow WordPress Database Queries. css-tricks, 2015.
- WordPress Codex, Database Description.
Custom Database Tables
- Used for both posts AND pages. This is where custom fields attached to a post/page would store their data.
- All content types are kept in the wp_posts table and are distinguished from one another by a post type. Default post types are post, page, attachment, revision, and navigation menu.
- Navigation Menu – nav_menu_item – This is not an entire menu but a single navigational item on a larger menu.
- For the taxonomy system, contains categories, tags, and custom taxonomies.
- When terms are hierarchical the relationship between one term and another is stored here. This table is being merged into wp_terms in the future.
- Used to determine which terms are actually the root level of a taxonomy.
Methods for Saving Data to Database
- Option Mechanism – For small amounts of data that rarely changes.
- Best practice is to use as few as possible, consider including multiple values in a single option field.
add_option($name, $value, $deprecated, $autoload);
- Only creates if it doesn’t already exist
$(option_)name = name of option;
$value = default value (optional);
$deprecated = no longer used, pass an empty string or null to it if you want to use
$autoload = should option be loaded by
wp_load_alloptions function? by default is yes.
- Retrieve the option from DB.
- Can be used to create an option if the deprecated or autoload params are not needed.