Timeline for WP_Query with LIKE returns strange query
Current License: CC BY-SA 4.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 4, 2020 at 6:44 | comment | added | Sam222 | Vitauts, Excellent help and thank you very much for pointing me where is the issue which is fixed now :-) | |
Feb 4, 2020 at 4:25 | answer | added | Jacob Peattie | timeline score: 3 | |
Feb 4, 2020 at 2:55 | review | Close votes | |||
Feb 11, 2020 at 8:46 | |||||
Feb 3, 2020 at 17:23 | comment | added | Vitauts Stočka |
explode creates array. Array may not be used in LIKE comparison. Use for loop on this array to create multiple LIKE conditions for each possible value and combine them in meta_query array with relation => 'OR' . See wordpress.stackexchange.com/questions/104060/… for combined meta_query example.
|
|
Feb 3, 2020 at 17:07 | comment | added | Sam222 | I am very sorry if i failed to provide the exact info. Here is my code of populating $arraydata = explode(',', $searchKeywords); | |
Feb 3, 2020 at 14:07 | comment | added | Vitauts Stočka |
Don't expect to get much help here if you are not trying to be helpful yourself. You were asked to show code populating $arraydata or at least its content. Instead you show query data. It takes time and effort to understand it, and its mostly irrelevant to your problem. Whatever you say, your value is array (print_r confirms it), and you can't compare arrays with LIKE. You need to create LIKE conditions for each of your array values and combine them in single meta query using OR.
|
|
Feb 3, 2020 at 12:13 | comment | added | Sam222 | Array ( [post_type] => lists [post_status] => publish [meta_query] => Array ( [0] => Array ( [key] => l_status [value] => Sold [compare] => IN )[1] => Array ( [key] => beds [value] => Array ( [0] => 0 [1] => 1) [compare] => IN [type] => NUMERIC )[2] => Array ( [key] => price [value] => Array ( [0] => 0 [1] => 1000000 )[compare] => BETWEEN [type] => NUMERIC )[3] => Array ( [key] => category [value] => Sold )[4] => Array ( [relation] => OR [0] => Array ( [key] => mp [value] => Array ( [0] => Deema )[compare] => IN )[1] => Array ( [key] => mp [value] => Array ( [0] => Deema )[compare] => LIKE ))) | |
Feb 3, 2020 at 12:11 | comment | added | Sam222 | $arraydata has the values and i can see on print_r which i am pasting in next comment | |
Feb 3, 2020 at 11:45 | comment | added | Jacob Peattie |
The SQL you've shared shows that there is no value. How are you populating $arraydata ?
|
|
Feb 3, 2020 at 11:41 | comment | added | Sam222 | $arraydata contains only one value i am looking to compare such as $arraydata='Deen' so that query should return all records having word Deen as Deen1, Deen 2, Deen 3 | |
Feb 3, 2020 at 11:34 | comment | added | Jacob Peattie |
I am trying to explain the problem, but you're ignoring me. What is inside $arraydata ?
|
|
Feb 3, 2020 at 11:33 | comment | added | Sam222 | Sorry Jacob inside array variable there are values like Deen in my below query: After tweak i am getting all possible records now regardless of my keyword. Is there anything wrong i am doing: ( mt5.meta_key = 'pr' AND mt5.meta_value LIKE '{6998fadab679fa902a65bccda33565e90707e29805a823569989b7f24beab57b}{6998fadab679fa902a65bccda33565e90707e29805a823569989b7f24beab57b}' ) ) ) ) AND wp_posts.post_type = 'lists' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID | |
Feb 3, 2020 at 11:32 | comment | added | Jacob Peattie |
IN is for checking if a value is in an array. LIKE is for comparing strings. They are for different things. You can't just use them interchangeably. You've ignored my question: What is inside the $arraydata variable? Is it a string, or an array?
|
|
Feb 3, 2020 at 11:08 | comment | added | Sam222 | But it should return the result. I can get correct result through IN comparison operator where as LIKE is not returning any result though i have the data which is why IN brings exact matched values. Below is the full array code: $loopArray['meta_query'][] = array('relation' => 'OR',array('key' => 'customdata1','value' => 'MyVal1','compare' => 'LIKE'),array('key' => 'customdata2','value' => 'MyVal2','compare' => 'LIKE')); | |
Feb 3, 2020 at 11:02 | comment | added | Jacob Peattie |
PS: The strange long codes are normal. They are placeholders for % . See: wordpress.stackexchange.com/questions/303935/…
|
|
Feb 3, 2020 at 11:01 | comment | added | Jacob Peattie |
What is inside $arraydata ? LIKE is used to compare strings. What values are you hoping to match with an array by using LIKE ? Do you want to check LIKE for each element in the array?
|
|
Feb 3, 2020 at 11:00 | history | edited | Jacob Peattie | CC BY-SA 4.0 |
added 94 characters in body
|
Feb 3, 2020 at 10:55 | review | First posts | |||
Feb 3, 2020 at 13:57 | |||||
Feb 3, 2020 at 10:52 | history | asked | Sam222 | CC BY-SA 4.0 |