[wp-hackers] Duplicate key=value pairs in wp_postmeta

Will Anderson wp-hackers at itsananderson.com
Thu Feb 26 14:27:21 GMT 2009


When you store multiple key/value pairs for a post, that key is turned into
an array.

I think it's pretty obvious from the function signature (with the $single
argument) that this is intentional.

One way I've used multiple values for one key before was for a portfolio. I
used a key called "featured" to indicate which clients I wanted in my
featured clients list. The value of that meta field indicated what service
they were featured for. Having duplicate key/value pairs allowed me to
indicate that a client was to be featured in multiple service categories.

Now I know this sounds like something that should be done with tags, but I
was already tagging ALL client posts with the services they had used, so I
needed a way to differentiate the featured clients. I also couldn't use
Cagetories for this because I was using the category name in the permalink
structure and placing a post in the "Portfolio" and the "Featured" category
would cause problems.

Another way to use multiple values for a key is to support pseudo categories
for pages (which can then be used in page lists).

So anyway, that was a long winded way of saying that allowing multiple
values for one key is important. It doesn't break the "unique list"
relational algebra paradigms used by the database manager because WordPress
assigns each {postid, key, value} a unique metaid.

On Thu, Feb 26, 2009 at 7:11 AM, scribu <scribu at gmail.com> wrote:

> I was trying to delete duplicate custom fields from postmeta. A duplica
> custom field means that for the same post you have:
>
> key = value
> key = value
>
> I think a unique(post_id, meta_key,meta_value) constraint would a good way
> to avoid this problem in the future, as I can't see any practical use for
> having the same custom field and value more than once for the same post.
>
> --
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Will Anderson
http://www.itsananderson.com/


More information about the wp-hackers mailing list