【Wordpress】投稿のカテゴリを指定して固定ページなどにカスタムフィールドの内容を出力させる方法
タイトルまんまだが、
投稿でNEWSを使ってそれをnews一覧として固定ページを作り、page-news.phpに表示させる。
前に書いた記事でも行けるが、これでもいけたのでメモしておく。
hiromode.hatenablog.com
12 <?php 13 $newslist = get_posts( array( 14 'category_name' => 'news', //特定のカテゴリースラッグを指定 15 'posts_per_page' => -1 //取得記事件数 16 )); 17 foreach( $newslist as $post ): 18 setup_postdata( $post ); 19 ?> 20 <dl> 21 <dt></dt> 22 <dd> 23 <a href="<?php the_permalink(); ?>"> 24 <?php echo get_field('category' , $post->ID );?> 25 <?php the_title(); ?> 26 </a> 27 </dd> 28 </dl> 29 <?php endforeach; 30 wp_reset_postdata(); 31 ?>