0

I would like to select all categories of my blog with count and date of create. I know that I have to convert post_date to specific month and then group my select by month(date) and category. However I don't know how to get all categories via SQL. Here is example for one post. I get only basic information but nothing about category.

$querystr = "
SELECT distinct $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE
$wpdb->posts.post_status = 'publish' 
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_date < NOW()
AND $wpdb->posts.ID = 1
ORDER BY $wpdb->posts.post_date DESC
";
$res = $wpdb->get_results($querystr, OBJECT);

The chellenge is to get category of posts via this query. I need to this that way because as a result I need to make an array of: date (as moth and year, format YYYYMM), category, count(*).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.