unstick_post

Un-stick a post.

Description

unstick_post( (int) $post_id ); 

Sticky posts should be displayed at the top of the front page.

Parameters (1)

0. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( 'unstick_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = unstick_post($post_id); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function unstick_post( $post_id ) { 
  2. $stickies = get_option('sticky_posts'); 
  3.  
  4. if ( !is_array($stickies) ) 
  5. return; 
  6.  
  7. if ( ! in_array($post_id, $stickies) ) 
  8. return; 
  9.  
  10. $offset = array_search($post_id, $stickies); 
  11. if ( false === $offset ) 
  12. return; 
  13.  
  14. array_splice($stickies, $offset, 1); 
  15.  
  16. $updated = update_option( 'sticky_posts', $stickies ); 
  17.  
  18. if ( $updated ) { 
  19. /** 
  20. * Fires once a post has been removed from the sticky list. 
  21. * @since 4.6.0 
  22. * @param int $post_id ID of the post that was unstuck. 
  23. */ 
  24. do_action( 'post_unstuck', $post_id );