wpseek.com
WordPress开发者和主题制作者的搜索引擎



stick_post › WordPress Function

Since2.7.0
已弃用n/a
stick_post ( $post_id )
参数:
  • (int) $post_id Post ID.
    Required: Yes
定义在:
文档:

Makes a post sticky.

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


源码

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

	if ( ! is_array( $stickies ) ) {
		$stickies = array();
	} else {
		$stickies = array_unique( array_map( 'intval', $stickies ) );
	}

	if ( ! in_array( $post_id, $stickies, true ) ) {
		$stickies[] = $post_id;
		$updated    = update_option( 'sticky_posts', array_values( $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 );
	}
}