Un-sticks a post.
Description
Sticky posts should be displayed at the top of the front page.
Parameters
$post_id
intrequired- Post ID.
Source
function unstick_post( $post_id ) {
$post_id = (int) $post_id;
$stickies = get_option( 'sticky_posts' );
if ( ! is_array( $stickies ) ) {
return;
}
$stickies = array_values( array_unique( array_map( 'intval', $stickies ) ) );
if ( ! in_array( $post_id, $stickies, true ) ) {
return;
}
$offset = array_search( $post_id, $stickies, true );
if ( false === $offset ) {
return;
}
array_splice( $stickies, $offset, 1 );
$updated = update_option( 'sticky_posts', $stickies );
if ( $updated ) {
/**
* Fires once a post has been removed from the sticky list.
*
* @since 4.6.0
*
* @param int $post_id ID of the post that was unstuck.
*/
do_action( 'post_unstuck', $post_id );
}
}
Hooks
- do_action( ‘post_unstuck’,
int $post_id ) Fires once a post has been removed from the sticky list.
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.