unstick_post( int $post_id )
- Since
- 2.7.0
- Source
wp-includes/post.php:3323
Description
Sticky posts should be displayed at the top of the front page.
Compatibility
- WordPress
- since 2.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$post_idint- Post ID.
Performance profile
How much work a call to unstick_post() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Moderate
- Scaling
- Constant
- Instructions
- 10–47
- Plugin surface
- 1 hook
- Called by
- 6
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 50.
Third-party callbacks on 'post_unstuck' run inside this call, and their cost is not bounded by anything here.
6 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
do_action()called directly - cacheobject cache
wp_cache_get()one call below unstick_post() - serializeserialisation
maybe_unserialize()one call below unstick_post()
Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost unstick_post() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_array($stickies) | 10 | get_option() |
is_array($stickies) && !$post_id | 24 | get_option(), array_map(), array_unique(), array_values() |
is_array($stickies) && $post_id && $offset === false | 32 | get_option(), array_map(), array_unique(), array_values(), array_search() |
is_array($stickies) && $post_id && $offset !== false | 43 | get_option(), array_map(), array_unique(), array_values(), array_search(), array_splice(), update_option() |
is_array($stickies) && $post_id && $offset !== false | 47 | get_option(), array_map(), array_unique(), array_values(), array_search(), array_splice(), update_option(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 50 | 10–47 | 4 | |
| 8.5 | 50 | 10–47 | 4 | |
| 8.4 | 50 | 10–47 | 4 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 53 | 10–50 | 4 | |
| 8.2 | 53 | 10–50 | 4 | |
| 8.1 | 53 | 10–50 | 4 | |
| 7.4 | 53 | 10–50 | 4 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while unstick_post() runs, in this order:
- do_action( post_unstuck )actionline 3354 (+31 into the body)
Fires once a post has been removed from the sticky list.
Uses · 3
- get_option()Retrieves an option value based on an option name.
- update_option()Updates the value of an option that was already added.
- do_action()Calls the callback functions that have been added to an action hook.
Used by · 6
- WP_REST_Posts_Controller::create_item()Creates a single post.
- WP_REST_Posts_Controller::update_item()Updates a single post.
- _reset_front_page_settings_for_post()Resets the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed.
- bulk_edit_posts()Processes the post data for the bulk editing of posts.
- edit_post()Updates an existing post with values provided in `$_POST`.
- wp_xmlrpc_server::_toggle_sticky()Encapsulates the logic for sticking a post and determining if the user has permission to do so.
Source code
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 ); }}Changelog
Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.