Skip to content

Instantly share code, notes, and snippets.

@montes
Created March 25, 2015 16:35
Show Gist options
  • Save montes/c51930467c2b33564b1d to your computer and use it in GitHub Desktop.
Save montes/c51930467c2b33564b1d to your computer and use it in GitHub Desktop.
Mysql query joining multiple cusfom fields (Wordpress)
SELECT wp_5_posts., meta1., meta2.*
FROM wp_5_posts
INNER JOIN wp_5_postmeta as meta1 ON wp_5_posts.ID = meta1.post_id
INNER JOIN wp_5_postmeta as meta2 ON meta2.meta_key = REPLACE(meta1.meta_key, 'acf_starting_date', 'acf_is_date_range')
AND meta1.post_id = meta2.post_id
WHERE wp_5_posts.post_status = 'publish'
AND wp_5_posts.post_type = 'event'
AND meta1.meta_key LIKE 'acf_date_list_%_acf_starting_date'
AND meta1.meta_value = '20150325'
GROUP BY wp_5_posts.ID ORDER BY wp_5_posts.post_date DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment