Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

Post Meta

Spent some lunch hours this week working on “post meta” hacks for WordPress. This will allow users to add arbitrary extra fields to their blog posts. Stuff like “current mood”, “now reading”, “listening to”, etc. Some prototype functions have been added to CVS, but the interface for actually adding data to posts hasn’t been done yet. We’re still discussing exactly how we’re going to implement the template functions for the new data. In my test blog, I just made a function that spits the data out as a list of key:value pairs, basically.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in WordPress and tagged . Bookmark the permalink.

7 Responses to Post Meta

  1. Alex says:

    Dougal, are you using a serialized array/object for the meta?

  2. Dougal says:

    I’ve added a new wp_postmeta database table. The structure is simple, just four fields: meta_id, post_id, meta_key, meta_value. The tricky part was converting that flat structure into a hierarchical struct. I build a $post_meta_cache object in wp-blog-header.php which contains the metadata for the currently selected set of posts. That way, each page view only requires one extra query to fetch the metadata.

  3. Alex says:

    Was there a reason you decided not get it in the same query with a LEFT JOIN?

  4. Alex says:

    Oops, sorry was still stuck in my serialized thought process, a JOIN probably wouldn’t work well since there is a one to many relationship there.

  5. Dougal says:

    Yeah, I almost started to do a join, but I quickly saw that it was going go get really messy trying to do it that way. That’s why I switched to just building a ‘cache’ variable with the metadata for the currently selected set of posts.

    It’s only one extra query per page load, so it shouldn’t be a big deal. I just have to wonder how well optimized MySQL’s IN clause is when the $post_id_list gets big.

  6. This post is very nice and really enjoyed it. This post have very useful information. so, thanks for posting it.

  7. This is truly a decent and enlightening, containing all data furthermore greatly affects the new innovation. A debt of gratitude is in order for sharing it

Leave a Reply

%d bloggers like this: