Skip to content

Instantly share code, notes, and snippets.

@redroot
Created October 5, 2012 08:23
Show Gist options
  • Select an option

  • Save redroot/3838739 to your computer and use it in GitHub Desktop.

Select an option

Save redroot/3838739 to your computer and use it in GitHub Desktop.
Wordpress: Find posts with a specific meta key
# swap out 'videoid' for whichever meta keys you want
SELECT A.ID, B.post_id, A.post_title, A.post_date FROM
(SELECT ID,
post_date, post_title
FROM wp_posts
WHERE post_status = "publish"
) as A
JOIN
(SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE meta_key = "videoid") as B
ON A.ID = B.post_id
ORDER BY A.post_date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment