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
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- Using is_main_query to select custom post type on certain page
- Show Sticky Post at the top but do not show again in the loop?
- Filtering out child category posts from parent category archive not working
- Elementor posts custom query based on tag [closed]
- pre_user_query vs pre_get_posts
- Seach and categories not working when ignoring sticky posts in main loop
- Pull posts from all categories if quantity is not met?
- Modify query to exclude certain ids and certain parents and its corresponding children
- When to use WP_query(), query_posts() and pre_get_posts
- When should you use WP_Query vs query_posts() vs get_posts()?
- Get post ids from WP_Query?
- Should I use Pre Get Posts or WP_Query
- Nested meta_query with multiple relation keys
- Using pre_get_posts with WP_Query
- Some doubts about how the main query and the custom query works in this custom theme?
- Wp get all the sub pages of the parent using wp query
- why ignore_sticky_posts in sticky post query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- What is “main query”? [duplicate]
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Using OR conditions in meta_query for query_posts argument
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- Order posts by ID in the given order
- How to uniquely identify queries?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Sticky Posts & Posts Per Page [closed]
- Query Multiple Post types each with own meta query
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Get posts by menu ID
- Get the number of posts from the current page results
- Changing Posts Per Page and offset with pre_get_posts
- How to exclude latest x posts from a paginated query?
- WordPress Custom Query to show posts from last x years
- Slow SQL_CALC_FOUND_ROWS Query
- Query Custom Meta Value with Increment
- “pre_get_posts” firing on every query
- RSS feed with specific keyword
- How to know which one is the main query?
- Get posts by meta data OR title
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- get query’s query string
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- Multiple orderby parameters in pre_get_posts() action
- Display Posts by modifying the where clause only for my query
- SQL Statement generated by WP_Query not producing expected results
- Use Transient API to cache queries for all posts in all categories?
- How do I create my own nested meta_query using posts_where / posts_join?
- wp_query for the first sticky, then display the rest of the posts excluding the first sticky
- Sorting Posts by custom field
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- Best practice for multiple queries on page
- Query with pre_get_posts to get pagination
- Recommended way to drop a pending query (in pre_get_posts)?
- How to Get All Posts but the Private ones?
- Single page theme that uses pages for the content
- All sticky posts are returned in custom query
- WordPress custom search form with pre_get_posts not work
- Transient pagination not working properly
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- How to find out what “Blog pages show at most” is set to [duplicate]
- order by multiple meta keys in pre_get_posts
- WP_Query Performance Issues with meta_query
- wp_transients | wp_object_cache VS SESSIONS & Cookies?
- Multiple search queries on one page
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Pass the same object to multiple widgets in a template with one query
- WP_Tax_Query with post_tag not working
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Retrieve or Query Pages by ID
- How to Modify Taxonomy Archive Page with Search Parameter?
- Include Sticky Posts in Page Post Count for custom query
- Query sticky posts with thumbnails
- Using pre_get_posts on a specific core/query block
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Transient caching for wp query
- How do you query wordpress posts using a math formula between multiple meta field values?
- Searching through different categories on different pages code is not working
- How add a custom posttype name using ACF field to a query post array
- How to display future posts – modified query still yields 404
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- Sticky Post default functionality with WP_Query is ignored when using AJAX
- pre_get_posts filter meta_query without conflicting existing meta_query
- Including only current user’s posts in search
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?