unstick_post() WordPress Function

The unstick_post() function is used to unstick a post from the sticky post pool. This function takes a single parameter, the post ID of the post to be unstuck.

unstick_post( int $post_id ) #

Un-stick a post.


Description

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


Top ↑

Parameters

$post_id

(int)(Required)Post ID.


Top ↑

Source

File: wp-includes/post.php

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 );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More