I was trying to list 20 recent posts, and put a post from custom post type on every 5th item. So it's like:
- Post
- Post
- Post
- Post
- Post
- Custom Post Type
- Post
- Post
- Post
- Post
- Post
- Custom Post Type .. and so on.
Here's what I did so far. It's working but the custom post types is still duplicating, even when the orderby set to random.
<?php $counter = 1;
$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 20) );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li class="group">
Post Content
</li>
<?php
if ($counter % 5 == 0){
$inner_query = new WP_Query(array( 'post_type' => 'custom-type', 'posts_per_page' => 1, 'orderby' => 'rand'));
while ($inner_query->have_posts()) : $inner_query->the_post(); ?>
<li>Custom Post Type Content</li>
<?php endwhile;
}
$counter++ ;
endwhile; ?>
How to prevent duplicate posts on the custom post type?
Thanks!