Skip to content

Instantly share code, notes, and snippets.

@jo-snips
Created January 17, 2013 22:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jo-snips/4560655 to your computer and use it in GitHub Desktop.
Save jo-snips/4560655 to your computer and use it in GitHub Desktop.
Get posts of a certain post type only if a certain meta field is not blank and split names returned in rows into new columns.
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(wp_posts.post_title, ' ', 1), ' ', -1) as memberfirst,
SUBSTRING_INDEX(SUBSTRING_INDEX(wp_posts.post_title, ' ', 2), ' ', -1) as memberlast,
wp_postmeta.meta_value
FROM wp_posts, wp_postmeta
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_posts.post_type = 'member'
AND wp_posts.post_status = 'publish'
AND wp_postmeta.meta_key = 'email'
AND wp_postmeta.meta_value != ''
ORDER BY wp_posts.post_date DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment