我正在編寫一個腳本,它將以可讀的佈局提取wp_usermeta。Wordpress解壓wp_usermeta
我有SQL象下面這樣:
select distinct(user_id), meta_value as suburb from wp_usermeta where meta_key = 'suburb' order by user_id
現在是有辦法,我們可以包括所有其他領域藏漢使用SQL查詢加盟右邊的列,使結果出來一個表所以我可以使用這個CSV導出?
UPDATE 25/SEP/2011,12:34 pm: 無所謂傢伙,我發現我的答案參考下面的sql !!!
SELECT
u.id, u.user_login,
MIN(CASE m.meta_key WHEN 'title' THEN m.meta_value END) AS title,
MIN(CASE m.meta_key WHEN 'first_name' THEN m.meta_value END) AS first_name,
MIN(CASE m.meta_key WHEN 'last_name' THEN m.meta_value END) AS last_name,
MIN(CASE m.meta_key WHEN 'suburb' THEN m.meta_value END) AS phone,
MIN(CASE m.meta_key WHEN 'state' THEN m.meta_value END) AS state,
MIN(CASE m.meta_key WHEN 'country' THEN m.meta_value END) AS country,
MIN(CASE m.meta_key WHEN 'postcode' THEN m.meta_value END) AS postcode,
MIN(CASE m.meta_key WHEN 'contact_no' THEN m.meta_value END) AS contact_no,
MIN(CASE m.meta_key WHEN 'email' THEN m.meta_value END) AS email,
MIN(CASE m.meta_key WHEN 'occupation' THEN m.meta_value END) AS occupation,
MIN(CASE m.meta_key WHEN 'workplace' THEN m.meta_value END) AS workplace,
MIN(CASE m.meta_key WHEN 'maternitybg' THEN m.meta_value END) AS maternitybg,
MIN(CASE m.meta_key WHEN 'trainingdate' THEN m.meta_value END) AS trainingdate,
MIN(CASE m.meta_key WHEN 'traininglocation' THEN m.meta_value END) AS traininglocation,
MIN(CASE m.meta_key WHEN 'coltraining' THEN m.meta_value END) AS coltraining,
MIN(CASE m.meta_key WHEN 'trainingyear' THEN m.meta_value END) AS trainingyear,
MIN(CASE m.meta_key WHEN 'coltraining' THEN m.meta_value END) AS coltraining,
MIN(CASE m.meta_key WHEN 'isinstructor' THEN m.meta_value END) AS isinstructor,
MIN(CASE m.meta_key WHEN 'gender' THEN m.meta_value END) AS gender,
MIN(CASE m.meta_key WHEN 'idf_indig_tsi' THEN m.meta_value END) AS idf_indig_tsi,
MIN(CASE m.meta_key WHEN 'idf_ct_ld' THEN m.meta_value END) AS idf_ct_ld,
MIN(CASE m.meta_key WHEN 'comments' THEN m.meta_value END) AS comments
FROM wp_users u
LEFT JOIN wp_usermeta m ON u.ID = m.user_id
AND m.meta_key IN ('title', 'first_name', 'last_name', 'suburb', 'state', 'country', 'postcode', 'contact_no', 'email', 'occupation', 'workplace', 'maternitybg', 'trainingdate', 'traininglocation', 'coltraining', 'isinstructor', 'gender', 'idf_indig_tsi', 'idf_ct_ld', 'comments')
GROUP BY u.ID
希望這有助於人們尋找這個解決方案!
呃...你一定需要一個純粹的SQL解決方案?爲什麼不使用WP API呢? – vzwick
我想用get_user_meta作爲WP API,並且生成到csv不起作用。 – user952543