You can try:
add_action('update_option_sticky_posts', function( $old_value, $value ) {
$featured_args = array(
'post__in' => $value,
'post_status' => 'publish',
'no_found_rows' => true
);
// The Featured Posts query.
$featured = new WP_Query( $featured_args );
// Proceed only if published posts with thumbnails exist
if ( $featured->have_posts() ) {
while ( $featured->have_posts() ) {
$featured->the_post();
if ( has_post_thumbnail( $featured->post->ID ) ) {
$featured_post_ids[] = $featured->post->ID;
}
}
set_transient( 'featured_post_ids', $featured_post_ids );
}
}, 10, 2);
I suppose you have the post IDs on the sticky_posts
option that’s why you are querying with that in the WP_Query