Count WordPress posts by year with SQL

How can i count all WordPress posts published in a certain year(for eg. 2010) directly from the database using SQL?

PS: I managed to do it using the WordPress Api query_posts() function, but i would also like the sql query for it.

Related posts

Leave a Reply

2 comments

  1. Assuming you are interested in the published posts:

    SELECT COUNT(*)
    FROM wp_posts
    WHERE YEAR(post_date) = 2010
    AND post_type = 'post'
    AND post_status = 'publish'
    

    where wp_posts is the default posts table name, adjust with whatever prefix you chose if you changed it.