Skip to content

Instantly share code, notes, and snippets.

@corysimmons
Created February 11, 2019 20:27
Show Gist options
  • Save corysimmons/8960317c61619e40f106ff7a5e6d9815 to your computer and use it in GitHub Desktop.
Save corysimmons/8960317c61619e40f106ff7a5e6d9815 to your computer and use it in GitHub Desktop.
Combine wp_users and wp_usermeta into a single table with columns (for wp_users) and a big JSON object (for all the wp_usermeta junk).
SELECT
u.id,
u.user_login,
concat('{ ' , group_concat(concat(m.meta_key, ': ''', m.meta_value, '''')) , ' }' ) AS meta
FROM
wp_users AS u
JOIN
wp_usermeta AS m
WHERE
u.id = m.user_id
GROUP BY
u.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment