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

  • Home
  • SEARCH
  • 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 8131961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:13:35+00:00 2026-06-06T09:13:35+00:00

Taking a PHP array of terms with variable length (i.e. it could be 50

  • 0

Taking a PHP array of terms with variable length (i.e. it could be 50 terms, it could be 400), what’s the most efficient way of searching my database for each of these terms?

The search I’m trying to do is quite straightforward. For each term, I’d like to do:

SELECT id, post_title FROM wp_posts WHERE post_title LIKE %term%

Obviously I can run a foreach in PHP and run multiple MySQL queries, but I’d imagine this to be hugely inefficient.

The code I’ve most recently tried involves multiple OR statements, but with ~100ish terms it appears to run very slowly.

I have no idea if something like this would work?

SELECT id, post_title FROM wp_posts WHERE post_title LIKE %term1%, %term2%, %term3%, %term4%, [...]

Can I use a more efficient SQL statement, or should I be looking at this in a different way?

  • 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-06T09:13:37+00:00Added an answer on June 6, 2026 at 9:13 am

    Stock MySQL could handle this kind of search using

    MATCH (post_title) AGAINST ('term1 term2 term3 term4')
    

    To do this search you will need to add Full Text index into the table using

    ALTER TABLE wp_posts ADD FULLTEXT INDEX ft_key1(post_title);
    

    This would be way faster than LIKE %term%, but please note that Full-Text indexes are only supported in MyISAM tables (InnoDB supported this syntax since MySQL 5.6).

    However as your data grow bundled MySQL search speed might become an issue. In this case I would suggest to use external search engine like Solr or Sphinx.

    If you decided to switch to Sphinx you may want to take a look on this guide http://astellar.com/2011/12/replacing-mysql-full-text-search-with-sphinx/

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

Sidebar

Related Questions

PHP's list keyword is nice for taking out variables from an array $a as
I'm taking array output from a command-line program and parsing it into a PHP
I have written a code for taking JSON data from a PHP and putting
I'm taking a look at some random Icecast playlists (available here: http://dir.xiph.org/index.php ) and
This is simple, but I am taking an entire directory listing (in PHP with
I'm taking a break from Project Euler to learn some PHP/HTML for kicks and
I am new to taking an object oriented approach with php...actually I have a
1 <?php 2 class ACL 3 { 4 var $perms = array(); //Array :
I have a solution to the below problem in PHP. But it is taking
I have an array in my PHP application, and I need to develop a

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.