I need to join POSTS with CUSTOM TABLE and POSTMETA. I am keeping track of popular posts in the custom table but I only want posts returned that have a specific postmeta value.
I searched and could not find a tut.
Here is what I 'think' I should do... but it doesn't work when done by hand in phpmyadmin.
SELECT (post info) FROM posts p INNER JOIN custom_table t ON p.ID = t.ID INNER JOIN post_meta m ON p.ID = m.ID WHERE m.metakey = 'mykey' AND post_type = 'post' AND post_date < '$now' AND post_date > '$lastmonth' ORDER BY postcount DESC LIMIT 5");
Do I need to inner join the post meta as a separate sub query?