1

I have a query running which prevents posts without various criteria from appearing, one of these is the necessity to have a featured image. Sticky posts however seem to end up in the query regardless. How can I achieve this?

    $args = array(
            'posts_per_page' => $articles_no,
            'meta_key' => '_thumbnail_id',
            'post__not_in' => $a_empty_titles,
            // remove post formats as per theme options ( using $hide from above )
            'tax_query' => array(
                    array(
                        'taxonomy' => 'post_format',
                        'field' => 'slug',
                        'operator' => 'NOT IN',
                        'terms' => $hide
                    )
                )
            );
        $fp_query = new WP_Query( $args ); ?>
            <ul class="thumbnails">
                <?php 
                $thumbnail_span = "span4";
                if( $fp_query->have_posts() ) : while( $fp_query->have_posts() ) : $fp_query->the_post(); ?>

                ... Typical Formatting Follows ...
                ... Posts without featured images should have been excluded but "sticky" posts seem to persist

1 Answer 1

1

Per the Codex article on WP Query:

ignore_sticky_posts (boolean) - ignore sticky posts or not. Default value is 0 - don't ignore sticky posts. Note: ignore/exclude sticky posts being included at the beginning of posts returned, but the sticky post will still be returned in the natural order of that list of posts returned.

Adding 'ignore_sticky_posts' => 1 to your $args array will stop sticky posts from showing up when you don't want them. Then 'meta_key' => '_thumbnail_id', can succeed at filtering out posts without featured images.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.