A little over a year ago, I wrote a post on how to use WP_Meta_Query whenever you have a set of keys you want to use to help pull back information from the database.
What about the case, though, when you have a number of different keys that would result in creating a really long array for the WP_Meta_Query class? For example, what if you had to loop through a collection of data before even setting up the query?
On some level, it might feel that like the natural thing to do would be to:
- iterate through the collection of keys,
- dynamically build up the results,
- combine them into a single result set,
- then work with whatever you’re given.
But doesn’t that sound a bit cumbersome (let alone slow)?
When it comes to using the WordPress API, I do what I can to stick to it before talking, say, directly to the database but there are also times where it makes sense to write a raw query than to write some type of clever code just to get the WordPress API to work. Continue reading