How to fetch all WordPress posts with featured image?

In WordPress 3 there is Featured Image functionality. How do i fetch all posts that have a featured image with them? Here is my current custom loop:

$loop = new WP_Query( array( 'posts_per_page' => 15 ) );


This should work:

$loop = new WP_Query( array( 'posts_per_page' => -1, 'meta_key' => '_thumbnail_id' ) );

I haven't tested this, though. Also, this will probably fetch all posts and pages. Use 'post_type' => 'post' to limit it to blog posts.

I don't believe you need any special loops defined for that to work.

Though you do need to add some small snippets into your functions.php

like this one:

<?php add_theme_support ( 'post-thumbnails' ); ?>

after apply the above code to functions.php file, your theme will support Featured Images and you will see a new link @ the bottom right of your Post Add / Edit interface.

This guide will help you, if you are looking for more info regarding this : How to Use Wordpress Featured Image Feature

Need Your Help

Comment indenting seems messed up in clojure-mode

emacs clojure tabs

In clojure-mode emacs is indenting my semi colon comments with 5 tabs. Even if it is the first line in an empty file this occurs.

Android: EditText cannot gain focus after being re-enabled

android focus android-widget android-edittext

I have a TabHost with three tabs. The first tab's content is the Intent of a custom activity who's contentview is a relative layout containing two EditTexts and two CheckBoxes (and a button).