yuheijotaki.com

WP_Query 投稿IDを配列に格納する

初回の WP_Query で $posts_id に投稿IDを配列に格納し、
次の WP_Query ではそれらをループに含まない

<?php
	$count = 0;
	$args = array(
		'post_type' => 'post',
		'posts_per_page' => 10,
		'order' => 'DESC',
		'meta_key' => 'META_KEY',
		'meta_value' => 'META_VALUE'
	);
?>
<?php $wp_query = new WP_Query( $args ); ?>
<?php if($wp_query -> have_posts()): ?>
<?php while($wp_query -> have_posts()): $wp_query->the_post();?>
	<h1><?php the_title(); ?></h1>
	<?php $posts_id[$count] = get_the_ID(); ?>
	<?php $count = $count + 1; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>

<?php $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 10, ‘order’ => ‘DESC’, ‘post__not_in’=> $posts_id ); ?> …