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.
Post Meta-
Subscribe
Follow Me
Sponsors
-
-
-

Referrals
-
Recent Posts
-
On This Day...
- 2003: Powered by WordPress
- 2003: Redirection
- 2004: The Parrot Says...
- 2005: I take it back...
Lifestream
-
Dougal I've had two (not small) cups of coffee. I had lunch and a diet coke. So why do I still feel like I could go nap for a few hours? Oh yeah. It's because our %#*$ cat woke us up at 3 a.m.— 14h ago via Facebook
-
First 50 people to use discount code 'wcbhm5off' get $5 off admission to WordCamp Birmingham (Sept 18-19)! http://bit.ly/b2WMqP #wcbhm10 [dougal]— 15h ago via Twitter
-
Dear Yankees: We Southerners love how you make fun of 'grits', but gobble down 'polenta' like it's some exotic delicacy. #jokesonyou [dougal]— 15h ago via Twitter
-
Checked in at La Rumba Cuban Cafe— 16h ago via Foursquare
-
Checked in at sure sight eye care— 17h ago via Foursquare
-




5 Comments
Dougal, are you using a serialized array/object for the meta?
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.Was there a reason you decided not get it in the same query with a LEFT JOIN?
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.
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.