save_post_{CPT} not updating the 'sticky_posts' option
add_action( save_post_{CPT}, 'update_sticky', 15, 1 );
function update_sticky( $post_id ) {
$stickies = get_option( 'sticky_posts' );
if ( ! in_array( $post_id, $stickies ) ) {
$stickies[] = $post_id;
update_option( 'test', $stickies);
update_option( 'sticky_posts', $stickies );
}
}
- It does work for
test
option I created for testing, but it doesn't work for existingsticky_posts
option, although everything is the same. - It does work for both if I hardcode the $post_id, like:
$stickies[] = 123;
- Tried it in
functions.php
file, as well as in the class in which I am registering the CPT, same results -test
is working, whilesticky_posts
is not. - Tried different action priorities, 5, 10, 15, 99
Any ideas?
Topic save-post sticky-post options Wordpress
Category Web