How do I make wp_get_archives show me months where only pages were created?

The wp_get_archives() function runs a filter on its WHERE clause–it’s called getarchives_where. You could use this to modify the query to only include pages rather than posts (which is the hard-coded default).

I haven’t tested this yet, but try it out:

add_filter('getarchives_where','my_archives_filter');

function my_archives_filter($where_clause) {

  return "WHERE post_type="page" AND post_status="publish"";

}

Then, just use the wp_get_archives function the way you normally would.

Obviously, this will affect the wp_get_archives function sitewide, so if you use wp_get_archives for grabbing a post archive somewhere else on your site, you’ll have to wrap the add_filter in something that recognizes the context.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)