Advertisement
rAthus

[WP] [SQL] exporter CPT avec metas

Jun 17th, 2024 (edited)
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.64 KB | None | 0 0
  1. -- sélectionne les CPT type "commune" pour en exporter l'ID, le titre, et les métas "cp", "lat", lng" et "shapes"
  2. SELECT p.ID,
  3.        p.post_title,
  4.        MAX(CASE WHEN pm.meta_key='cp' THEN pm.meta_value ELSE NULL END) AS 'cp',
  5.        MAX(CASE WHEN pm.meta_key='lat' THEN pm.meta_value ELSE NULL END) AS 'lat',
  6.        MAX(CASE WHEN pm.meta_key='lng' THEN pm.meta_value ELSE NULL END) AS 'lng',
  7.        MAX(CASE WHEN pm.meta_key='shapes' THEN pm.meta_value ELSE NULL END) AS 'shapes'
  8. FROM vtx_posts p LEFT JOIN vtx_postmeta pm ON (pm.post_id=p.ID)
  9. WHERE p.post_type='commune' AND p.post_title!='Brouillon auto'
  10. GROUP BY p.ID
  11. ORDER BY p.ID ASC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement