Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As we all know, a design pattern that is used frequently in Wordpress' DB code is the idea of persisting data for a particular object (blog/post/comment), indexed with a particular name or key.

We see this pattern used in the following standard tables:

  • wp_options
  • wp_commentmeta
  • wp_postmeta

As far as I can tell, the motivation for this design decision was to enable plugin/theme authors to persist data easily (e.g. by using custom fields) without having to modify the database schema. It would seem to me that there are few other advantages to this approach, since it is significantly slower and makes it harder to implement complex queries.

What are the other advantages to this approach, if any?


UPDATE: Reading info on the drawbacks of this approach:

share|improve this question
    
I have no idea of database schemas or performance... But, just for the sake of the argument, can you reference your statements? Like in Wikipedia, "citation needed"... –  brasofilo Dec 21 '12 at 2:20
    
Thanks for your comment! I've updated the question. –  rinogo Dec 21 '12 at 2:30
1  
Options are meant to be key-value pairs, there's nothing wrong there. However in the case of post meta, the answers you linked from stackoverflow are relevant here as well: this is just poor design. –  onetrickpony Dec 21 '12 at 4:43

1 Answer 1

up vote 2 down vote accepted

The ability to store abstract key-value pairs without modifying the database structure is the reason. Without that, WordPress loses much of its flexibility. I can't speak for others, but the single largest reason why I develop atop WordPress is its flexible nature.

To quote one of your links above,

Usually the reasoning behind doing what you are doing is because the domains need to be "user definable". If that is the case then even I am not going to push you towards creating tables on the fly...

While it's true that it forces queries to be more complex, and a little slower, the benefits far outweigh the costs. But, hey, it's all about what you're doing. Don't use a hammer to bang in a screw. If you still want to use WordPress, but need to run complex queries on steady, structured sets of data, check out Pods.

I hope this helps you out!

share|improve this answer
    
-1. WP actually loses flexibility, just take a look of all the questions here asking solutions for sorting or searching posts by meta values. Also queries are a lot slower because of all the joins you're forced to perform. You didn't mention any definite benefit of using this pattern. –  onetrickpony Dec 21 '12 at 4:50
2  
@OneTrickPony First off, thanks for taking the time to explain the downvote. Second, "just take a look of all the questions here asking solutions for ..." is not an argument; you could insert anything at the end of that sentence ;-). I stand behind my argument that the sole benefit is flexibility. If you wanted to store a new option on your site, or a new field associated with users or posts, and you had to modify the structure of the database, it would get out of hand very quickly. But hey, WP is open source, if you can do better, the community welcomes it! –  Matthew Boynes Dec 21 '12 at 5:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.