WordPress カスタム投稿のアーカイブリスト出力
◯functions.php
function my_custom_post_type_archive_where( $where, $args ){ $post_type = isset( $args['post_type'] ) ? $args['post_type'] : 'post'; $where = "WHERE post_type = '$post_type' AND post_status = 'publish'"; return $where; } add_filter( 'getarchives_where', 'my_custom_post_type_archive_where', 10, 2 );
◯テンプレートファイル $args = array( ‘post_type’ => ‘POST_TYPE_NAME’, ‘type’ => ‘monthly’, ‘echo’ => 0 ); $list = wp_get_archives($args); echo ‘<ul>’ . $list . ’</ul>’;