Reputation: 729
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 ) );
Upvotes: 14
Views: 11919
Reputation: 2780
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
Upvotes: -2
Reputation: 4591
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.
Upvotes: 30