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
testoption I created for testing, but it doesn't work for existingsticky_postsoption, although everything is the same. - It does work for both if I hardcode the $post_id, like:
$stickies[] = 123; - Tried it in
functions.phpfile, as well as in the class in which I am registering the CPT, same results -testis working, whilesticky_postsis not. - Tried different action priorities, 5, 10, 15, 99
Any ideas?
Topic save-post sticky-post options Wordpress
Category Web