Skip to content

Instantly share code, notes, and snippets.

@alt-karate
Created June 21, 2021 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alt-karate/d1eee85e257428d536fe68d5d0d17a23 to your computer and use it in GitHub Desktop.
Save alt-karate/d1eee85e257428d536fe68d5d0d17a23 to your computer and use it in GitHub Desktop.
<?php
$custom_posts = get_posts(array(
'post_type' => 'カスタム投稿タイプスラッグ', // 投稿タイプ
'posts_per_page' => 6, // 表示件数
'orderby' => 'date', // 表示順の基準
'order' => 'DESC', // 昇順・降順
'tax_query' => array(
array(
'taxonomy' => 'タクソノミースラッグ', //タクソノミーを指定
'field' => 'slug', //ターム名をスラッグで指定する
'terms' => 'タームスラッグ', //表示したいタームをスラッグで指定
'operator' => 'IN'
),
)
));
global $post;
if($custom_posts): foreach($custom_posts as $post): setup_postdata($post); ?>
<!-- ループはじめ -->
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p><?php the_time('Y/m/d') ?></p>
<p><?php the_excerpt(); ?></p>
<!-- ループおわり -->
<?php endforeach; wp_reset_postdata(); endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment