wordpress カスタム投稿 ターム毎表示 ×カスタムフィールド表示

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$taxonomy_name = 'タクソノミー名';
$taxonomys = get_terms($taxonomy_name);
 
if(!is_wp_error($taxonomys) && count($taxonomys)):
  foreach($taxonomys as $taxonomy):
 
    $arg = array(
      'posts_per_page' => -1,
      'post_type' => 'カスタム投稿タイプ名',
      'tax_query' => array(
        array(
          'taxonomy' => $taxonomy_name,
          'field'    => 'slug',
          'terms'    => $taxonomy->slug,
          )
        )
    );
 
    $tax_posts = get_posts($arg);
    if($tax_posts):
?>
    <h2><?php echo esc_html($taxonomy->name); ?></span></h2>
    <ul>
      <?php foreach($tax_posts as $tax_post): ?>
      <li><a href="<?php echo get_permalink($tax_post->ID); ?>"><?php echo esc_html($tax_post->post_title); ?></a></li>
      <?php endforeach; ?>
    </ul>
<?php  endif; endforeach; endif; ?>
PAGE TOP