-1

If I search "sales order" it's fetching "sales order" and "sales orders" in results. It's fetching the result with "s" also.

But if I search "sales orders" it's fetching "sales orders" only but I want "sales order" will also fetch.

I am using php mysql query.

SELECT DISTINCT * FROM wp_posts as p 
    inner join wp_postmeta as pm on pm.post_id = p.ID 
    where (p.post_type = 'abc' or p.post_type = 'xyz') 
    and p.post_title LIKE '%sales order%' 
    or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
    GROUP by p.ID 
    ORDER BY p.id DESC
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
ANkit Joshi
  • 91
  • 1
  • 8

4 Answers4

1

Try with this without "%"

p.post_title LIKE 'sales order'
Ravi Patel
  • 641
  • 1
  • 10
  • 18
0

You can also try like this

and (p.post_title LIKE '%sales order%'  OR p.post_title LIKE '%sales orders%' )

I hope this will solve your issue.

Sachin Raghav
  • 452
  • 5
  • 14
0

I am not much sure about this query but you can check as

SELECT DISTINCT * FROM wp_posts as p 
inner join wp_postmeta as pm on pm.post_id = p.ID 
where (p.post_type = 'abc' or p.post_type = 'xyz') 
and p.post_title LIKE '%sales%' AND  p.post_title LIKE '%order%'
or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
GROUP by p.ID 
ORDER BY p.id DESC

OR

SELECT DISTINCT * FROM wp_posts as p 
inner join wp_postmeta as pm on pm.post_id = p.ID 
where (p.post_type = 'abc' or p.post_type = 'xyz') 
and p.post_title LIKE '%sales%order%'
or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
GROUP by p.ID 
ORDER BY p.id DESC
Nikita Agrawal
  • 235
  • 1
  • 11
0
use MySQL Full text search,check if FULLTEXT indexes are there

SELECT DISTINCT * FROM wp_posts as p 
    inner join wp_postmeta as pm on pm.post_id = p.ID 
    where (p.post_type = 'abc' or p.post_type = 'xyz')
    match (p.post_title) against ('sales order')
    or (pm.meta_key = 'xyzkeyword' and pm.meta_value LIKE '%sales order%') 
    GROUP by p.ID 
    ORDER BY p.id DESC
Kedar Limaye
  • 1,041
  • 8
  • 15