WP_Query not working with “s” parameter

I am having a strange issue related to WP_Query. I am using a custom search function search for a post, but when I am executing this query, it giving me all the post along with the post that I searched on top of the list.
So rather than searching for the post, its just order them.
To investigate this issue, I enabled the SAVEQUERIES’ and added this line in wp-config file.

SELECT SQL_CALC_FOUND_ROWS ogw_posts.ID FROM ogw_posts WHERE 1=1
AND ogw_posts.post_type = ‘post’ AND ((ogw_posts.post_status = ‘publish’))
ORDER BY (CASE WHEN ogw_posts.post_title LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}MyBar Protein{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’
THEN 1 WHEN ogw_posts.post_title LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}MyBar{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’ AND ogw_posts.post_title LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}Protein{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’
THEN 2 WHEN ogw_posts.post_title LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}MyBar{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’ OR ogw_posts.post_title LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}Protein{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’
THEN 3 WHEN ogw_posts.post_excerpt LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}MyBar Protein{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’
THEN 4 WHEN ogw_posts.post_content LIKE ‘{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}MyBar Protein{f7c619c23504ea8383a54427834d0c1521a69f37690ff8623346044639a7b578}’
THEN 5 ELSE 6 END), ogw_posts.post_date DESC LIMIT 0, 20

When I execute the same query on the development server, I am receiving the following query:

SELECT SQL_CALC_FOUND_ROWS ogw_posts.ID FROM ogw_posts WHERE 1=1 AND
(((ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_excerpt LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_content LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’)) AND ((ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_excerpt LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_content LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’)))
AND ogw_posts.post_type = ‘seller’ AND ((ogw_posts.post_status = ‘publish’)) ORDER BY (CASE WHEN ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’
THEN 1 WHEN ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’ AND ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’
THEN 2 WHEN ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’ OR ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’
THEN 3 WHEN ogw_posts.post_excerpt LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’
THEN 4 WHEN ogw_posts.post_content LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’
THEN 5 ELSE 6 END), ogw_posts.post_date DESC LIMIT 0, 20

If you compare those two SQL query, you will clearly see that one condition is complete issing in the first query. that’s:

(((ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_excerpt LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_content LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}MyBar{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’)) AND ((ogw_posts.post_title LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_excerpt LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’) OR (ogw_posts.post_content LIKE ‘{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}Protein{5a204c777fc9bdec1c57dce2279014bb129676a75d6f5d3307492b11fc5bac24}’)))

I am not sure why this happening, both site using the same WordPress version and code.
Can anyone, please explain me the issue?

Read more here:: WP_Query not working with “s” parameter

Leave a Reply

Your email address will not be published. Required fields are marked *