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.

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

2 Answers 2

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

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

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.