stick_post

The timeline below displays how wordpress function stick_post has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Makes a post sticky.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
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);
    }
}

WordPress Version: 5.7

/**
 * Make a post sticky.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
function stick_post($post_id)
{
    $post_id = (int) $post_id;
    $stickies = get_option('sticky_posts');
    $updated = false;
    if (!is_array($stickies)) {
        $stickies = array($post_id);
    } 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);
    }
}

WordPress Version: 5.5

/**
 * Make a post sticky.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
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);
    }
}

WordPress Version: 4.6

/**
 * Make a post sticky.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
function stick_post($post_id)
{
    $stickies = get_option('sticky_posts');
    if (!is_array($stickies)) {
        $stickies = array($post_id);
    }
    if (!in_array($post_id, $stickies)) {
        $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);
    }
}

WordPress Version: 3.7

/**
 * Make a post sticky.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
function stick_post($post_id)
{
    $stickies = get_option('sticky_posts');
    if (!is_array($stickies)) {
        $stickies = array($post_id);
    }
    if (!in_array($post_id, $stickies)) {
        $stickies[] = $post_id;
    }
    update_option('sticky_posts', $stickies);
}