Last active
June 27, 2019 07:18
-
-
Save alt-karate/1038c0447f1b77ae0b5b2b182210aa0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 投稿にアーカイブ(投稿一覧)を持たせるようにします。 | |
* ※ 記載後にパーマリンク設定で「変更を保存」してください。 | |
*/ | |
function post_has_archive( $args, $post_type ) { | |
if ( 'post' == $post_type ) { | |
$args['rewrite'] = true; | |
$args['has_archive'] = 'newsrelease'; // ページ名 | |
} | |
return $args; | |
} | |
add_filter( 'register_post_type_args', 'post_has_archive', 10, 2 ); | |
function get_archives_by_fiscal_year( $args = '' ) { | |
global $wpdb, $wp_locale; | |
$defaults = array ( | |
'post_type' => 'post', | |
'limit' => '', | |
'format' => 'html', | |
'before' => '', | |
'after' => '', | |
'show_post_count' => false, | |
'echo' => 1 | |
); | |
$r = wp_parse_args( $args, $defaults ); | |
extract ( $r, EXTR_SKIP ); | |
if ( '' != $limit ) { | |
$limit = absint( $limit ); | |
$limit = ' LIMIT ' . $limit; | |
} | |
$arcresults = (array) $wpdb->get_results( | |
"SELECT YEAR(ADDDATE(post_date, INTERVAL -3 MONTH)) AS `year`, COUNT(ID) AS `posts` | |
FROM $wpdb->posts | |
WHERE post_type = '$post_type' AND post_status = 'publish' | |
GROUP BY YEAR(ADDDATE(post_date, INTERVAL -3 MONTH)) | |
ORDER BY post_date DESC | |
$limit" | |
); | |
return $arcresults; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment