Skip to content

Instantly share code, notes, and snippets.

@nicomollet
Created November 21, 2018 15:47
Show Gist options
  • Select an option

  • Save nicomollet/c3e830ee7c85dfc527089bd9acd9cfe5 to your computer and use it in GitHub Desktop.

Select an option

Save nicomollet/c3e830ee7c85dfc527089bd9acd9cfe5 to your computer and use it in GitHub Desktop.
Export WordPress users with meta
SELECT
t1.ID, t1.user_email,
MAX(CASE WHEN t2.meta_key = 'first_name' THEN meta_value END) AS first_name,
MAX(CASE WHEN t2.meta_key = 'last_name' THEN meta_value END) AS last_name,
MAX(CASE WHEN t2.meta_key = 'paying_customer' THEN meta_value END) AS paying_customer,
MAX(CASE WHEN t2.meta_key = 'billing_title' THEN meta_value END) AS billing_title
FROM th_users AS t1
INNER JOIN th_usermeta AS t2 ON t1.ID = t2.user_id
GROUP BY t1.ID, t1.user_email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment