Query posts: how to exclude results if post is in multiple categories

This is probably not a “pure” way to do it, but this code make an array of featured post ids and then excludes them from future get_posts.

$featuredPosts = get_posts('category'=>'D','numberposts'=>'-1');
$fPId = array();
foreach ($featuredPost as $currentPost)
{
  array_push($fPId,$currentPost->ID);
}
$aPosts = get_posts('category' => 'a', 'exclude'=>$fpId);
$bPosts = get_posts('category' => 'b', 'exclude'=>$fpId);
$cPosts = get_posts('category' => 'c', 'exclude'=>$fpId);

Leave a Comment