lafif-a
5/7/2015 - 6:39 AM

[Wordpress][Database] Display meta_value as column

[Wordpress][Database] Display meta_value as column

SELECT p.ID, p.post_type, p.post_status, m.* FROM wp_posts p LEFT JOIN
( SELECT  
  post_id, 
  GROUP_CONCAT(if(meta_key = 'campaign_description', meta_value, NULL)) AS 'description', 
  GROUP_CONCAT(if(meta_key = 'campaign_start', meta_value, NULL)) AS 'start', 
  GROUP_CONCAT(if(meta_key = 'campaign_end', meta_value, NULL)) AS 'end', 
  GROUP_CONCAT(if(meta_key = 'campaign_priority', meta_value, NULL)) AS 'priority' 
FROM wp_postmeta
GROUP BY post_id ) m
ON m.post_id = p.ID
WHERE p.post_type = 'campaign' AND p.post_status = 'publish'
AND m.start = '05/07/2015'
AND m.end = '05/20/2015'