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.

My application allows users to add tags to an image (similar to facebook). Each tag can consist of up to 8 attributes and there is currently no limit on the amount of tags a user can add.

At the moment, tag information is stored across 3 post meta key/value pairs. Each post meta value is serialized before storing.

We're approaching a rewrite of this functionality and I wanted to ask for some advice on the best approach to storing tag data.

IMO there are two approaches:

  1. post meta key/value for each tag/attribute (this has the potential to create a huge dataset - n tags times 8 attributes)

  2. A new table just for tags

Both approaches would avoid storing serialized data, which I think is what I need to achieve.

Which is the better approach?
Is a third option possibly even more feasible?

share|improve this question

2 Answers 2

Avoid serialized whenever you can. It is slow to read and you cannot really search for it.

Use custom tables – more than one:

  1. One for the relationship between users, tags and images: user_id, tag_id and image_id.
  2. One for tag meta data, your attributes, if I understand that right: tag_id, meta_1, meta_2

Now you can look up for each attachment ID if there is an entry for the user, and then look up the meta data from the meta table.

share|improve this answer
    
Thanks, I'll have a play around with a sample schema based on your suggestion –  Oldie Apr 23 '13 at 11:11

Rather than using a custom table or post meta to store the tag information you will probably find a simpler solution if you investigate the Custom Taxonomy support within WordPress.

You can register one (or more) custom taxonomies against the attachment post type.

The following Codex pages are a good place to start:

You may also find inspiration in existing WordPress plugins which provide similar functionality such as http://plugins.trac.wordpress.org/browser/matts-community-tags/trunk

share|improve this answer
    
Thanks Peter I'll look into custom taxonomies. –  Oldie May 3 '13 at 13:34
    
I've had a play around with taxonomies and how I think it could work for tags with the application and I've got a couple of potential approaches. Feedback would be much appreciated. pastebin.com/79tnV1Ev –  Oldie May 3 '13 at 15:07
    
@Oldie your pastebin link doesn't work for me –  Peter Westwood May 7 '13 at 23:48
    
I've created a gist - gist.github.com/anonymous/dc2b058d7a36ae57c240 –  Oldie May 8 '13 at 9:53
    
So looking at this the first approach is going to work more successfully because the second approach makes the data really hard to query using the WordPress APIs. –  Peter Westwood May 8 '13 at 15:47

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.