stick_post

Make a post sticky.

Description

stick_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( 'stick_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 = stick_post($post_id); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function stick_post( $post_id ) { 
  2. $stickies = get_option('sticky_posts'); 
  3.  
  4. if ( !is_array($stickies) ) 
  5. $stickies = array($post_id); 
  6.  
  7. if ( ! in_array($post_id, $stickies) ) 
  8. $stickies[] = $post_id; 
  9.  
  10. $updated = update_option( 'sticky_posts', $stickies ); 
  11.  
  12. if ( $updated ) { 
  13. /** 
  14. * Fires once a post has been added to the sticky list. 
  15. * @since 4.6.0 
  16. * @param int $post_id ID of the post that was stuck. 
  17. */ 
  18. do_action( 'post_stuck', $post_id );