This is a generalization of a question that I've been struggling with for a while. My case is that I have a WordPress site with multiple "post types" (e.g. Articles, Blog Posts, Products, etc.). As is common practice these days, I want to display search results from each post type in separate categories.
The problem I have is in structuring the search. Should I run a separate database query for each post type, or should I run one big query and separate everything out via PHP? I tend to lean towards the latter, but the problem I'm running into is with pagination. I would probably have to not set any LIMIT
on the query because if I had several matches from one post type, the search would not return any results from the other post types.
So, from a performance and general best practices stand point, is it better to have one big query without a LIMIT
clause, or to run several queries for each search?
Note: This is similar to a question I asked on the WordPress Stack Exchange site a while back. I accepted the multiple query solution then, but I'm still pretty unsure about this.