WordPress 前後の記事を取得・出力
<?php $previous_post = get_previous_post(); ?> <?php $next_post = get_next_post(); ?> <?php if (!empty( $previous_post )): ?> <?php $args = array( 'post_type' => 'POST_TYPE_NAME', 'posts_per_page' => '1', 'post__in' => array( $previous_post->ID ) ); ?> <?php $loop = new WP_Query( $args ); ?> <?php if($loop -> have_posts()): ?> <?php while($loop -> have_posts()): $loop->the_post();?> <!-- loop --> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_postdata(); ?> <?php endif; ?>