This should do:
// Get sticky posts
$sticky = get_option('sticky_posts');
rsort($sticky);
$sticky = array_slice($sticky, 0, 3);
// Check if current post is inside
foreach ($sticky as $key => $value)
if ($value === $GLOBALS['post']->ID) {
// ... and remove
unset($sticky[$key]);
break;
}
$query = new WP_Query(
array(
'post__in' => $sticky,
'ignore_sticky_posts' => 1,
)
);
If you want to have 3 posts (no matter what), you have to do it like so (minimally changed):
// Get sticky posts
$sticky = get_option('sticky_posts');
rsort($sticky);
// Check if current post is inside
foreach ($sticky as $key => $value)
if ($value === $GLOBALS['post']->ID) {
// ... and remove
unset($sticky[$key]);
break;
}
$sticky = array_slice($sticky, 0, 3);
$query = new WP_Query(
array(
'post__in' => $sticky,
'ignore_sticky_posts' => 1,
)
);
// EDIT: added break
after current post ID has been found and removed, in case you have a great number of sticky posts.
post__in
andpost__not_in
in the same query.