Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created July 26, 2012 18:53
Show Gist options
  • Save micahwave/3183795 to your computer and use it in GitHub Desktop.
Save micahwave/3183795 to your computer and use it in GitHub Desktop.
Group by order by
"
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