[wp-trac] [WordPress Trac] #18410: WP_Query should unserialize serialized data before matching

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 15 12:13:09 UTC 2011


#18410: WP_Query should unserialize serialized data before matching
-------------------------+----------------------
 Reporter:  Doggie52     |       Owner:
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  Query        |     Version:  3.2.1
 Severity:  normal       |  Resolution:  wontfix
 Keywords:               |
-------------------------+----------------------

Comment (by Doggie52):

 Replying to [comment:1 scribu]:
 > First of all: arrays are not the prefered way of storing data in custom
 fields; you can have multiple custom field values with the same key, for
 the same post. All the more reason if you plan on querying against custom
 field values.
 Say I have a list of checkboxes - would I store their values all under one
 key? Comma separated? That sounds like much more of a hassle than simply
 storing them in an array. You mention storing them under one key - that
 would still make it an array (albeit one with only one entry) and would
 still cause it to become serialized, right?

 > Secondly getting all the custom fields, unserializing them and then
 looking for a match would be a really inefficient way to go about it.
 I was rather thinking of checking if the input is an array, if the DB
 entry is serialized and only if both are, unserializing the DB entry for
 matching.

 > Instead, you can call maybe_serialize() on the value you are trying to
 match against.
 If by "the value you are trying to match against" you mean the input
 array, I did call maybe_serialize() on that, but to no avail. The DB entry
 is being treated as a string and will only match if there is an exact
 match with the input array. I'd rather like to have the flexibility of
 choosing either an exact or partial match.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18410#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list