Skip to main content
3 of 5
added 76 characters in body
tfrommen
  • 9.2k
  • 7
  • 39
  • 59

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->ID === $GLOBALS['post']->ID)
        // ... and remove
        unset($sticky[$key]);

$query = new WP_Query(
    array(
        'post__in' => $sticky,
        'ignore_sticky_posts' => 1,
    )
);

// EDIT
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->ID === $GLOBALS['post']->ID)
        // ... and remove
        unset($sticky[$key]);

$sticky = array_slice($sticky, 0, 3);

$query = new WP_Query(
    array(
        'post__in' => $sticky,
        'ignore_sticky_posts' => 1,
    )
);

// EDIT: now accessing global post object.

tfrommen
  • 9.2k
  • 7
  • 39
  • 59