Question

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 ) );
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top