W3cubDocs

/WordPress

stick_post( int $post_id )

Make a post sticky.

Description

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

Parameters

$post_id

(int) (Required) Post ID.

Source

File: wp-includes/post.php

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

	if ( ! is_array( $stickies ) ) {
		$stickies = array();
	}

	$stickies = array_map( 'intval', $stickies );

	if ( ! in_array( $post_id, $stickies, true ) ) {
		$stickies[] = $post_id;
	}

	$updated = update_option( 'sticky_posts', $stickies );

	if ( $updated ) {
		/**
		 * Fires once a post has been added to the sticky list.
		 *
		 * @since 4.6.0
		 *
		 * @param int $post_id ID of the post that was stuck.
		 */
		do_action( 'post_stuck', $post_id );
	}
}

Changelog

Version Description
2.7.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/stick_post