How to fetch all WordPress posts with featured image? How to fetch all WordPress posts with featured image? wordpress wordpress

How to fetch all WordPress posts with featured image?


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