You can try to fetch posts, that don’t have a featured image, with:
$ppp = 5; // posts per page
/**
* Fetch $ppp posts, without thumbnails, in a given category:
*/
$args = array(
'cat' => 1,
'posts_per_page' => $ppp,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS',
),
),
);
$myposts = get_posts( $args );
But what if there are not enough posts, without a featured image, in that category? Well, then we can just fill the rest with posts with a featured image:
/**
* Fetch $ppp-x posts in a given category, with thumbnails, if x > 0:
*/
if( $count = count( $posts ) < $ppp )
{
$args = array(
'cat' => 1,
'posts_per_page' => $ppp - $count,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS',
),
),
);
$myposts = array_merge( $posts, get_posts( $args ) );
}
Then you can setup your loop with:
global $post;
foreach( $myposts as $post )
{
setup_postdata( $post );
?><li><a href="https://wordpress.stackexchange.com/questions/173313/<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
}
wp_reset_postdata();
You might also want to make a check if you got enough posts within the corresponding category.
Notice that this is untested, but I hope you can modify this to your needs.
ps: If I remember correctly, @kaiser already solved something similar in the general case, with some extra flavors added 😉
I will add a link if I find it.
Update: Found it here, I think. There are some interesting answers over there.