WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several blocks of data to save into post meta, including 'file_property', 'workspace_property', 'user_property','access_type', 'usage_tracking'. Each block in itself is an array. Should I save them all as one post-meta, or save each single data sepeartely? I feel the post-meta table might be a bit too long if one post has 20 to 30 meta-key, but if all in one, I'm not sure if it's convinient when query or update, so to ask.

share|improve this question

In most cases its better to store the meta as a single array and in that save database queries.

The only down side to storing the data as an array is it's nearly impossible to query based on sirealized data.

So my rule is if i need to query based on that data the it gets its own field anything else goes in an array.

share|improve this answer

The only disadvantage is that arrays and objects need to converted to a storable value, so you get a a weird looking string as the meta value. In most cases this is not a problem, but it becomes one when the meta value (data) is large and you need to make queries that do value comparisons. Take WP's user capabilities as an example.

My advice is to avoid both solutions whenever possible. If your data consists of well defined representations, like values that can have only a-z characters for example, then you can implode/explode those values as needed. This way you can still keep them into a single meta field, but into a much nicer form than serialized / json_encoded data.

Is there any reason people not doing things this way?

You answered this yourself: you get a slightly faster query when reading it.

Ask yourself if you need to get posts ordered by access_type, user_property, or posts that have a specific access_type, user_property etc. If you do, then you have to create post meta for each of those.

share|improve this answer
thanks for your advice! I just edited my question. Could you give an example on how to cast my data to be a-z: 'property-a', 'property-b'.. or also do it on each element inside each block? And, an example of implode/explode ? – Jenny Dec 15 '11 at 15:35
Let's use an example - what kind of values does user_property take? – onetrickpony Dec 15 '11 at 18:34
user_propery =>array( 'role'=>'', access_time=>'', score=>'') – Jenny Dec 16 '11 at 0:27

Your Answer


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.