Last active
August 5, 2022 07:10
-
-
Save nathan-roberts/57f9d30e017f32acef0949e9a0859743 to your computer and use it in GitHub Desktop.
WP SQL Meta Query
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 | |
wp_posts.ID, | |
wp_posts.post_title, | |
bill.meta_value AS bill, | |
year.meta_value AS year, | |
chapter.meta_value AS chapter, | |
house.meta_value AS house | |
FROM | |
wp_posts | |
LEFT JOIN wp_postmeta AS bill ON wp_posts.ID = bill.post_id | |
AND bill.meta_key = 'bill' | |
LEFT JOIN wp_postmeta AS year ON wp_posts.ID = year.post_id | |
AND year.meta_key = 'year' | |
LEFT JOIN wp_postmeta AS chapter ON wp_posts.ID = chapter.post_id | |
AND chapter.meta_key = 'chapter' | |
LEFT JOIN wp_postmeta AS house ON wp_posts.ID = house.post_id | |
AND house.meta_key = 'house' | |
WHERE | |
wp_posts.post_status = 'publish' | |
AND wp_posts.post_type = 'product' | |
ORDER BY | |
wp_posts.post_title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment