Here is my query as is for a WP database.
$letters = $wpdb->get_col(
"SELECT DISTINCT LEFT(post_title,1) AS first_letter FROM $wpdb->posts
WHERE post_type = '$post_type' AND post_status = 'publish'
ORDER BY first_letter ASC"
);
It is a baby name database and I want to make a widget to separate male/female so I need to do a query like above but to get posts with only certain postmeta which below is the key and value I am looking for.
Key – spin2
Value – Male
How do I add this into the query since it is in a different table?
Thanks!
You just need to use an
INNER JOIN
: