Last active
August 29, 2015 13:56
-
-
Save chambaz/8848770 to your computer and use it in GitHub Desktop.
Query Wordpress for posts with associated meta data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT p.ID, | |
p.post_title, | |
p.post_date, | |
p.post_excerpt, | |
p.post_content, | |
MAX(CASE WHEN pm.meta_key = '_aioseop_description' then pm.meta_value ELSE NULL END) as meta_description, | |
MAX(CASE WHEN pm.meta_key = '_aioseop_title' then pm.meta_value ELSE NULL END) as meta_title | |
FROM wp_posts p LEFT JOIN wp_postmeta pm ON ( pm.post_id = p.ID) | |
WHERE p.post_status = 'publish' AND p.post_type = 'post' | |
GROUP BY p.ID, p.post_title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment