Skip to content

Instantly share code, notes, and snippets.

@b0n
Created May 30, 2013 05:13
Show Gist options
  • Save b0n/5675842 to your computer and use it in GitHub Desktop.
Save b0n/5675842 to your computer and use it in GitHub Desktop.
wordpress wp_get_archives で指定した月だけ取得する
/**
* 月を指定してwp_get_archivesを呼び出します
* @see common-sidebar.php
* @see wp-includes/general-template.php wp_get_archives()
*/
if ( ! function_exists( 'my_custom_post_type_archive_where' ) ) {
function my_custom_post_type_archive_where( $where, $args ){
if ($args['type'] != 'monthly')
return $where;
if (!isset($args['year']) || !is_numeric($args['year']))
return $where;
$where .= " AND YEAR(post_date) = '" . $args['year'] . "'";
return $where;
}
}
add_filter( 'getarchives_where', 'my_custom_post_type_archive_where', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment