I use a custom request to populate a slider, and then I have another section with a different request.
i've come up with something :
/* recup de la requete slider pour comparaison */
$slider_posts = request_slider();
/* requete pour peupler highlights */
$highlights_posts = request_highlights();
/* on retire les posts du slider */
$highlights_posts = array_diff_key($highlights_posts,$slider_posts);
Where request_slider() and request_highlights() are two differents request that use get_posts();
the returned array looks OK but somehow I think i'm doing it wrong, because i'm not used to working with arrays.
What do you think ? Is there a logical error in there ?
--- edit : find a better way to do so ---
Much simplier way as WP can use a argument for excluding IDs:
/* recup de la requete slider pour comparaison */
$slider_posts = request_slider();
/* extraction des ID */
foreach ($slider_posts as $slider_post) {
$slides_id[] = $slider_post->ID;
}
/* requete pour peupler highlights */
$highlights_posts = request_highlights($slides_id);
function request_highlights($exclude_ids) {
/* la requete qui va peupler le slider */
$args = array(
'numberposts' => 16,
'category' => null,
'orderby' => 'post_date',
'order' => 'DESC',
'post__not_in' => $exclude_ids,
);
return get_posts( $args );
}
So we just take the first request, loop it, and create a new array with the IDs. Then we use the post__not_with the IDs as argument to make the second request.
Works like a charm. Thanks Smashing Magazine !