Track your post ID
s.
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => '17,1',
'number' => '6'
);
$fcategories = get_categories($cat_args);
$used_ids = array();
foreach($fcategories as $fcategory) {
$post_args = array(
'posts_per_page' => 1,
'cat' => $fcategory->cat_ID
);
if (!empty($used_ids)) {
$post_args['post__not_in'] = $used_ids;
}
$fposts = new WP_Query($post_args);
if ($fposts->have_posts()) {
while($fposts->have_posts()) {
$fposts->the_post();
$used_ids[] = $post->ID;
get_template_part('post', 'homepage');
}
}
}
A couple of notes:
- There are a couple of syntax errors in your code
-
Don’t use
query_posts
.It should be noted that using this to replace the main query on a page
can increase page loading times, in worst case scenarios more than
doubling the amount of work needed or more. While easy to use, the
function is also prone to confusion and problems later on. See the
note further below on caveats for details.http://codex.wordpress.org/Function_Reference/query_posts (emphasis mine)