WordPress plugin that serialize custom fields data

Is there any WP plugin that is able to serialize custom fields data ?
My issue is the following:
e.g. You want to create “Book information” like post where you want to add e.g. Author + Price custom fields for each post… If you do it standard way WP will create for you 2 rows in table for every custom field you enter.
Assume you have 1000 books and every one has 5 custom fields, then its 5000 rows with custom fields data. I would like to have only one row for each post with custom fields data … so serialized.
Is that possible ?

Related posts

Leave a Reply

2 comments

  1. It might be possible, but you lose a lot of functionality that way. With individual rows for each field, you have the ability to search and index based on a field. Using your example, you could list books by price or by author.

    With serialized fields, you’d be forced to load all book information first, then parse the entire array on the server side to sort it before returning it to the browser. This involves much more overhead and would slow things down considerably.

    So while it would be possible to serialize the fields, it would not be a recommended use of custom fields. It seems your biggest concern here is the number of rows present in the database … and even with 1000 books with 5 custom fields, that’s not a significant problem. I’ve run WordPress installations with 10,000 posts each with 10 custom fields without any performance issues whatsoever.

  2. I’ve done something sort of similar. It takes some work to get the programming right… You have to capture the POST data when it’s inserted into the database. You could also query for all custom fields in a post, add them to an array, serialize and insert them, then delete the original entries.

    I’d hook the function in on the save_post action.

    The real problem is trying to update the records. Unserializing and populating a bunch of created-on-the-fly custom fields would be quite complicated.

    I don’t see 50,000 rows as prohibitive. Certainly less of a pain than trying to do things this way.