Yoan Cutillas
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Hacks
In reply to: Query works in phpmyadmin but not with $wpdbI have found a workaround, with three queries…
It seems that wordpress doesn’t supports SQL variables and that group_concat_max_len needs to be set in its own query.
$wpdb->query( 'SET SESSION group_concat_max_len = 1000000' ); $select_usermeta_columns_query = " SELECT GROUP_CONCAT( DISTINCT CONCAT( 'MAX( IF ( M.meta_key = ''', meta_key, ''', M.meta_value, NULL)) AS `', meta_key, '`' ) ) as select_usermeta FROM wp_usermeta as M;"; $select_usermeta_columns = $wpdb->get_var( $select_usermeta_columns_query ); $users_info_query = " SELECT *, " . $select_usermeta_columns . " FROM wp_users as U, wp_usermeta as M WHERE U.id = M.user_id GROUP BY U.id ; "; $users_info = $wpdb->get_results( $users_info_query, OBJECT );
But I don’t like this solution because it uses 3 queries instead of 1, and I need to pass $select_usermeta_columns directly in the query ($wpdb->prepare doesn’t work for column names).
Still looking for proper solutions 🙂
My bad, I do not have custom posts, I couldn’t have checked.
It’s fixed in Qtranlate X v3.4.6.6
Thanks !
Viewing 3 replies - 1 through 3 (of 3 total)