[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:24:58 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:3 dd32]:
 > > ou 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?
 >
 > Almost, Metakeys are not unique. For example, You can store multiple
 meta items, eg:
 > {{{
 > Post ID MetaName  MetaValue
 >   1       test     value1
 >   1       test     value2
 >   1       test     value3
 > }}}
 >
 > calling get_post_meta(1, 'test') would then return  array(value1,
 value2, value3).
 Calling get_post_meta() for my above example works - it is the querying
 with meta_query that doesn't work. Would it work for your example? I
 assume it would, since the MetaValues would be stored as strings and not
 arrays, right?
 > > 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.
 >
 > Take a step back, The querying/matching is done within the Database, ie.
 within the SQL. SQL doesnt understand PHP's serialized format, therefor,
 all SQL see's is a long string..
 > In order to do what you're suggesting, It would require loading ALL meta
 keys into memory, unserializing them (well, some of them), and then
 implementing a Database-style comparison function in-WordPresss.. It's
 reinventing the wheel.
 Maybe I'm not understanding it correctly, but I really do not see how
 calling is_serialized() and if so, maybe_unserialize() on one value in the
 database is ineffective. I'm not saying the SQL should do this check, but
 rather PHP. When inputting an array as value in the meta_query array,
 WP_Query could simply check if the value in the database is serialized and
 if so, unserialize it to enable matching.
 > It may be that you're using the wrong storage mechanism, You might for
 example, be better off storing it in a Taxonomy to allow easier querying..
 I will definitely look into that, having run into this wall of opposition
 :P .

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


More information about the wp-trac mailing list