Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:24:33+00:00 2026-06-09T21:24:33+00:00

This is a generalization of a question that I’ve been struggling with for a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:24:35+00:00Added an answer on June 9, 2026 at 9:24 pm

    In my experience, it is usually better to ask the database to do as little work as possible, and have PHP do most of the heavy lifting. It’s usually faster.

    So, I would try doing two very simple queries (one for each table) and then merging/sorting them with PHP code.

    If your data set is very big, or if your web host is crap, then your PHP script may run out of memory… then, and only then, it is a good idea to start hunting around for the right way to do it in MySQL (I suspect temporary tables might be the right place to look).

    But if you run into PHP’s performance limits, then I suspect anything you do in MySQL is actually going to be even slower and you’ll have to change your database structure to get good performance. One way to do this is to keep your existing table structure, but have a third table that contains duplicate data from all the tables – just for searching, and some code to keep everything in sync.

    For example, we have a table that contains every pdf document uploaded by the website’s users, and we have another table that contains every word that is in any document, and many-to-many linking table in between those.

    Whenever a new pdf is uploaded, we find every word in it, and insert records into the linking table. This way we never actually have to search in the PDF documents, we only search the index tables which have been structured to allow for fast searching.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a generalization of my previous question about pluralize filter: Does lift have
This is a generalization of the string contains substring problem to (more) arbitrary types.
My question is a slight generalization of this one . For sake of discussion,
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
This should be a simple one: I have an observableArray object called To in
I'm trying to model a specialization/generalization, leaning towards using class table inheritance (see this
Consider languages like Python or JavaScript that allow functions to be nested like this:
I have to make a decision regarding generalization vs polymorphism. Well the scenario is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.