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.
|
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. |
|||
|
|
|
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.
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.
|
|||||||
|