wordpressにアップしている全ての投稿(postタイプ毎)から記事をランダムで表示する方法
<?php
$args = array(
'post_type' => 'post', // 投稿タイプ
'post__not_in' => array($post -> ID),// 今読んでいる記事を除く
'posts_per_page' => 5, // 取得する件数
'orderby' => 'rand' // ランダムで記事を取得
);
$my_query = new WP_Query($args);
?>
<?php if ($my_query->have_posts()) :
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<!-- ここに記事コンテンツ -->
<div class="post">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
<h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php endwhile;
wp_reset_postdata();
endif; ?>