I could use some advise on how to structure my data for performance. I have a custom post type with a lot of custom meta data stored in the wp_postmeta
table as a serialized array under one meta key for each post. Now, I need to get some posts from that post type, and filter them by the meta data I have stored.
Right now, the only way I can think to do that is to get ALL the meta data for ALL of the posts of this type, then unserialize them into a massive PHP array, and then use foreach
loops to check them all one-by-one. This strikes me as a really bad/slow way to do things.
At this point, I’m thinking I should scrap my whole plan, and start from scratch using my own custom table. That’s just so un-wordpress though, and it would be a LOT of work. My other idea is to do what was suggested on this other question (meta_query with meta values as serialize arrays) and separate all the meta values into separate meta keys and then query them as shown on that question. The problem I see there is that that query doesn’t look like it will be particularly fast either, and my wp_postmeta
table would get HUGE.
Any ideas would be greatly appreciated.
If you want to have more control over the filtering of your posts then separating the meta values into separate keys is the best option to go about it. Also what you could do is, only the values that would be required while filtering could be separated and the rest of them could go into a serialized array.