Q1
Yes, you can store serialized arrays as a single meta key, eg:
update_post_meta( $post_id, 'my_items', array( 1, 2, 3, 4 );
Furthermore, you can store multiple values against a single meta key, eg:
add_post_meta( $post_id, 'my_items', 1 );
add_post_meta( $post_id, 'my_items', 2 );
The latter is preferred because meta queries can be more efficiently performed against them.
In the first example, there is a single row in the post_meta
table. In the second example, there are two rows.
So, in the second example, you can perform a query for posts which have a my_item
meta value of 2
without having to pull out and unserialize every my_item
entry in the database.
Many people, myself included, learned this the hard way.
Q2
I’m sorry I can’t answer the why, though I do know that serialization and unserialization can have performance implications for large data sets.