Jeff
Jeff

Reputation: 106

Wordpress SQL Post title search

I'm building a large custom search for a wordpress site that is functioning as a directory. Part of the search is using SQL to poll for multiple meta values, and the other part is by title. I can't seem get a simple SQL LIKE to work when polling the titles. Below is my code:

SELECT * FROM wp_posts WHERE post_type = 'business' AND post_status = 'publish' AND post_title LIKE 'Butler' ORDER BY post_title ASC

Upvotes: 0

Views: 2354

Answers (1)

p.campbell
p.campbell

Reputation: 100637

Use wildcards in your LIKE:

SELECT * FROM wp_posts 
WHERE post_type = 'business' 
AND post_status = 'publish' 
AND post_title LIKE '%Butler%' 
ORDER BY post_title ASC

Upvotes: 2

Related Questions