Query sticky posts with thumbnails

I need to display max 5 latest sticky posts that have a thumbnail. And I need to have accurate counting of the displayed posts. I’ve tried to exclude sticky posts without a thumbnail with meta_query, but with no luck. $sticky = get_option(‘sticky_posts’); if (empty($sticky)) { return; } $counter = 1; $r = new WP_Query(array( ‘posts_per_page’ … Read more

Include Sticky Posts in Page Post Count for custom query

This link solves the problem but it’s only for the main query. What if you are using a custom query? How can you modify the answer below: add_action(‘pre_get_posts’, ‘ad_custom_query’); function ad_custom_query($query) { if ($query->is_main_query() && is_home()) { //how can we for specific custom query? // set the number of posts per page $posts_per_page = 12; … Read more

Exclude expired sticky posts

I use the following code to exclude expired posts and it works fine but it doesn’t exclude expired sticky posts. //* Exclude expired posts add_action( ‘pre_get_posts’, ‘exclude_expired_posts’ ); function exclude_expired_posts( $query ) { if ( !is_admin() && $query->is_main_query() && !is_search() && !is_singular() && !is_date() ) { $meta_query = array ( ‘relation’ => ‘OR’, array( ‘key’ … Read more

“Sticky” posts for each category (archive.php)

I need to have the ability to have Sticky posts for each category. The simplest way to do this appeared to be to just create two loops on the page. This is what I wrote: <?php //Custom “sticky” loop $sticky_posts = new WP_Query(array( ‘post__in’ => get_option(‘sticky_posts’) )); if ($sticky_posts->have_posts()) : while ($sticky_posts->have_posts()) : $sticky_posts->the_post(); get_template_part(‘post-formats/content’, … Read more