今、'rewrite' => true,
と書かなくても、
global $wp_rewrite;
$wp_rewrite->flush_rules();
を書いてあればエラーにならず表示されることに気付きました。
functions.phpにこちらを書いてます。
/* カスタム投稿タイプの追加 */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'tokyo', /* post-type */
array(
'labels' => array(
'name' => __( '東京' ),
'singular_name' => __( '東京' )
),
'public' => true,
'menu_position' =>5,
/* ここから */
'supports' => array('title','editor','thumbnail',
'custom-fields','excerpt','author','trackbacks',
'comments','revisions','page-attributes')
/* ここまで */
) //array
); //register_post_type
global $wp_rewrite;
$wp_rewrite->flush_rules();
register_post_type( 'kanagawa', /* post-type */
array(
'labels' => array(
'name' => __( '神奈川' ),
'singular_name' => __( '神奈川' )
),
'public' => true,
'menu_position' =>6,
/* ここから */
'supports' => array('title','editor','thumbnail',
'custom-fields','excerpt','author','trackbacks',
'comments','revisions','page-attributes')
/* ここまで */
) //array
); //register_post_type
$wp_rewrite->flush_rules();
/* ここから */
register_taxonomy(
'tokyo-cat', /* タクソノミーの名前 */
'tokyo', /* tokyo投稿で設定する */
array(
'hierarchical' => true, /* 親子関係が必要なければ false */
'update_count_callback' => '_update_post_term_count',
'label' => '東京のカテゴリー',
'singular_label' => '東京のカテゴリー',
'public' => true,
'show_ui' => true
) //array
); //register_taxonomy
/* ここまでを追加 */
$wp_rewrite->flush_rules();
/* ここから */
register_taxonomy(
'kanagawa-cat', /* タクソノミーの名前 */
'kanagawa', /* kanagawa投稿で設定する */
array(
'hierarchical' => true, /* 親子関係が必要なければ false */
'update_count_callback' => '_update_post_term_count',
'label' => '神奈川のカテゴリー',
'singular_label' => '神奈川のカテゴリー',
'public' => true,
'show_ui' => true
) //array
); //register_taxonomy
/* ここまでを追加 */
$wp_rewrite->flush_rules();
}
/* カスタム投稿タイプの追加 ここまで */
index.phpにこちらを書いてます。
<?php
/* カスタム投稿タイプを表示する */
$loop = new WP_Query( array( 'post_type' => 'izu', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
/* カスタム分類を表示 */
<p class="taxonomies">
<?php echo get_the_term_list( $post->ID, 'izu-cat', 'タクソノミー', ', ', '' ); ?>
</p>
/* コンテンツ */
<div class="custom-post-content">
<?php the_content('続きを読む»'); ?>
</div>
<?php endwhile; /* カスタム投稿タイプを表示する ここまで */ ?>
<?php
/* カスタム投稿タイプを表示する */
$loop = new WP_Query( array( 'post_type' => 'east', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
/* カスタム分類を表示 */
<p class="taxonomies">
<?php echo get_the_term_list( $post->ID, 'east-cat', 'タクソノミー', ', ', '' ); ?>
</p>
/* コンテンツ */
<div class="custom-post-content">
<?php the_content('続きを読む»'); ?>
</div>
<?php endwhile; /* カスタム投稿タイプを表示する ここまで */ ?>