unstick_post

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

WordPress Version: 6.1

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

WordPress Version: 5.7

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

WordPress Version: 5.5

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

WordPress Version: 4.6

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

WordPress Version: 4.0

/**
 * Un-stick a post.
 *
 * Sticky posts should be displayed at the top of the front page.
 *
 * @since 2.7.0
 *
 * @param int $post_id Post ID.
 */
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);
    update_option('sticky_posts', $stickies);
}

WordPress Version: 3.7

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