I have bunch of custom post type footer elements with a meta key footer_element_meta_alignment. Now, I'm trying to fetch three latest posts, which meta_values are 1, 2 and 3. So, one post with each of those values.
How can I achieve this with single SQL Query?
This is my SQL Query so far:
"SELECT wposts.*, meta1.meta_value
FROM $wpdb->posts wposts, $wpdb->postmeta meta1
WHERE 1=1
AND wposts.post_type = 'footer_element'
AND wposts.post_status = 'publish'
AND wposts.ID = meta1.post_id
AND meta1.meta_key = 'footer_element_meta_alignment'
AND (meta1.meta_value = 1 OR meta1.meta_value = 2 OR meta1.meta_value = 3)
ORDER BY meta1.meta_value ASC";
That however fetches all elements with given meta values, and not only the latest one.
ANSWER
Answered my own question.