A query sorts posts by pageviews – this works perfectly. But I need to join wp_term_taxonomy.term_taxonomy_id too. Like this:
WHERE wp_term_taxonomy.term_taxonomy_id ='2'
the code:
$qstr = "
SELECT wposts.*
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
group by postid) pv
WHERE wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND wposts.ID = pv.postid
ORDER BY pv.pageviews DESC
LIMIT 10
";
I tried this:
$qstr = "
SELECT wposts.*, wp_term_taxonomy.term_taxonomy_id
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
group by postid) pv
WHERE wposts.post_status = 'publish'
INNER JOIN
wp_term_taxonomy
AND xxxx // dont know
WHERE wp_term_taxonomy.term_taxonomy_id = '13'
AND wposts.post_type = 'post'
AND wposts.ID = pv.postid
ORDER BY pv.pageviews DESC
LIMIT 10
";
Why are you using join? Won’t this work for you: