views:

35

answers:

2

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 ) );
A: 

You may find this helpful:

Sarfraz
I am wondering if there is a way to fetch all posts with featured images in one call, instead of getting posts and looping to check if they have images or not. I have strong feeling that there is a way and it is one of those one liner solutions, but I just don't know it now.
Giljed Jowes
+2  A: 

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.

John P Bloch
It works! Thanks!
Giljed Jowes