Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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