Created
July 26, 2012 18:53
-
-
Save micahwave/3183795 to your computer and use it in GitHub Desktop.
Group by order by
This file contains hidden or 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 g.*, p.ID as article_id, p.post_title as article_title | |
FROM $wpdb->posts AS g | |
LEFT JOIN $wpdb->postmeta AS pm ON pm.meta_value = g.ID | |
LEFT JOIN $wpdb->posts AS p ON pm.post_id = p.ID | |
LEFT JOIN $wpdb->postmeta AS pm2 ON pm2.post_id = g.ID | |
WHERE g.post_type = 'time_guest' | |
AND pm.meta_key = 'time_guest_author' | |
AND pm2.meta_key = 'time_guest_time100' | |
AND ( pm2.meta_value = 'on' OR pm2.meta_value = 1 ) | |
GROUP BY g.ID | |
ORDER BY p.post_date DESC | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment