I have this query in place in the index page of my site:
<?php $cats = array('0' => 'Politics',
'1' => 'Culture',
'2' => 'Campus',
'3' => 'Flashback'
);
// earlier queries supplied other ID's to skip - this is them
$skip = (array_merge($ids, $recentids, $scoopids));
foreach($cats as $k => $v) {
$array = array('showposts' => '2',
'category_name' => $v,
'post__not_in' => $skip,
);
$my_query = new WP_Query($array);
if($my_query->have_posts()) : ?>
Basically I have 4 categories that I want to loop through. They all have the exact same output - grabbing the first 2 posts in each category, and laying them all out exactly the same - so it didn't make sense to me to make 4 different queries just because the category was different. So I stuck 'em in an array to Loop through and be done with it.
It works fine, except for one thing: if a post is in multiple categories, it shows up twice in this groups of post listings. I want to be sure each post ID is unique to each category so there are no duplicates.
Is there a way to recursively apply the already-shown post->ID so if it's in the next loop, it'll skip it and move on to the next one?