user

WordPress Domain Model

Introduction

user

Naresh Bhatia

Naresh is a software architect in the Boston area. He started Archfirst after realizing that technologists spend too much time fighting technologies instead of solving real-world problems. Archfirst is a place where we can all learn best practices and techniques to make software development easier.


LATEST POSTS

JoinJS – An Alternative to Complex ORMs 10th August, 2015

MyBatis vs. Other ORMs 01st July, 2015

WordPress Domain Model

Posted on .

I recently switched this site to run on WordPress. For the amount of power WordPress provides, the underlying database is surprisingly simple, consisting of only 11 tables. Nevertheless, it took me a little while to understand the schema because everything is centered around posts and it was not obvious how other concepts such as pages and menus were supported.

After some research I learned that the term post comes from WordPress’ origin as a blogging platform. Since then WordPress has evolved into a powerful CMS, adding many more concepts. However the name post just stuck and has been overloaded to implement the newer concepts. Unfortunately, the database schema is not very useful in conveying these concepts. This is where a domain model would be more useful. The diagram below shows a domain model of WordPress, highlighting the domain concepts instead of implementation artifacts. Content is an abstract entity from which posts and other concrete entities are derived.

wp-domain-model

This model can be extended to show specific use cases for which you use WordPress. For example, a news site may use it to publish news articles, whereas an eCommerce site may use it to sell products. When designing such sites, it is useful to think in terms of domain entities like news and products instead of posts. Furthermore, you may want to explicitly show the attributes of these domain entities. For example, a news item belongs to a news section. This exercise will help you clearly define the requirements and how to map them to WordPress’ implementation. The domain model below shows a NewsItem as an extension of Content and belonging to a NewsSection.

custom-post-type

The logical concepts shown above can now be translated to a WordPress implementation. For example, you can add a Custom Post Type (CPT) called news_type having a custom field called news_section. You can refer to the articles below to learn more about Domain-Driven Design and implementing your domain in WordPress:

  1. Domain-Driven Design
  2. When Do You Need a Custom Post Type or Taxonomy in WordPress
  3. How to Create Custom Post Types in WordPress
  4. WordPress Custom Fields 101
profile

Naresh Bhatia

Naresh is a software architect in the Boston area. He started Archfirst after realizing that technologists spend too much time fighting technologies instead of solving real-world problems. Archfirst is a place where we can all learn best practices and techniques to make software development easier.

There are no comments.

Leave a Reply

View Comments (0) ...
Navigation