A WordPress-centric search engine for devs and theme authors



unstick_post ›

Since2.7.0
Deprecatedn/a
unstick_post ( $post_id )
Parameters:
  • (int) $post_id Post ID.
    Required: Yes
Defined at:
Codex:

Un-stick a post.

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



Source

function unstick_post( $post_id ) {
	$stickies = get_option( 'sticky_posts' );

	if ( ! is_array( $stickies ) ) {
		return;
	}

	if ( ! in_array( $post_id, $stickies ) ) {
		return;
	}

	$offset = array_search( $post_id, $stickies );
	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 );
	}
}