SELECT p2c.category_id AS cat_id,
COUNT(p2c.rel_id) AS numposts,
UNIX_TIMESTAMP(max(posts.post_date_gmt)) + '1' AS last_post_date,
UNIX_TIMESTAMP(max(posts.post_date_gmt)) AS last_post_date_gmt
FROM wp_post2cat p2c
INNER JOIN wp_posts posts ON p2c.post_id=posts.id
WHERE 1 = 1
AND posts.post_type = 'post'
AND posts.post_status = 'publish'
AND posts.post_date_gmt <= '2014-01-21 14:33:02'
GROUP BY p2c.category_id
ORDER BY numposts DESC
Jedno zapytań do bazy wpordpress.