Programming, WordPress

Get the list of year associated with the posts

WordPress has a global object variable $wpdb, which communicates with the WordPress database. We can read more about $wpdb in Codex.

To get the list of the year in the posts, you can do the following :


In the aforementioned code, if you wish to get the year associated with the custom post type update the post_type name with your custom post type.


Hits: 6

Filter and Hooks

SQL Query to get the archive / year by post type

For listing the published year of the particular post type, we can use the SQL as presented below.

Replace the ‘post_type’ with your own post type.

Hits: 7