stick_post( int $post_id )

Make a post sticky.


Description Description

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


Parameters Parameters

$post_id

(int) (Required) Post ID.


Top ↑

Source Source

File: wp-includes/post.php

2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
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 );
    }
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.