is_sticky

Check if post is sticky.

Description

is_sticky( (int) $post_id = 0 ); 

Sticky posts should remain at the top of The Loop. If the post ID is not given, then The Loop ID for the current post will be used.

Parameters (1)

0. $post_id — Optional. (int)
Post ID. Default is ID of the global $post.

Usage

  1. if ( !function_exists( 'is_sticky' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Post ID. Default is ID of the global $post. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_sticky($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function is_sticky( $post_id = 0 ) { 
  2. $post_id = absint( $post_id ); 
  3.  
  4. if ( ! $post_id ) 
  5. $post_id = get_the_ID(); 
  6.  
  7. $stickies = get_option( 'sticky_posts' ); 
  8.  
  9. if ( ! is_array( $stickies ) ) 
  10. return false; 
  11.  
  12. if ( in_array( $post_id, $stickies ) ) 
  13. return true; 
  14.  
  15. return false;