I have a simple mysql query in a php function (wordpress).
The function works with no problem, except when the result is with non English characters ( or non Latin) e.g. Hebrew, Arab, Chinese, Japanese...
The thing is , that the query works just fine if I remove the ORDER BY
and the LIMIT
commands. (see commented out in the code).
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
" . $hide_underscore . "
/* ORDER BY meta_key
LIMIT $limit */
" );
if ( $keys )
natcasesort($keys);
The keys themselves (meta_key) exist in the DB just fine, and other functions or query have no problem whatsoever using them (so it is not a locale, DB encoding , or character set problem..) also the natcasesort()
function does not seem to be the problem ..
It looks like it is a specific problem of the ORDER
and / or LIMIT
.
Is there a reason why just those commands are failing ? is there a solution ?
I have tried to remove (comment out) only ONE of the pair , but it still fails. only removing both will work.
UPDATE I
I forgot to mention
$hide_underscore ='HAVING meta_key NOT LIKE "\_%"'
or
$hide_underscore =''