如何编辑此条件以仅计算带有缩略图的帖子?
if ( $my_query->have_posts() && ( ( $my_query->post_count ) >= 3 ) )
您必须执行循环,因为缩略图关系不会自动解析:
$postsWithThumbs = 0;
while($my_query->have_posts()){
$my_query->the_post();
if(has_post_thumbnail())
$postsWithThumbs++;
}
wp_reset_postdata();
print $postsWithThumbs;
您必须以不同的方式检查它;
$post_with_thumbs = 0;
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ): $my_query->the_post();
if ( has_post_thumbnail()) {
$post_with_thumbs++;
}
endwhile;
}
wp_reset_query();
if ($post_with_thumbs >= 3) {
//do stuff
}
I'm not sure if this still works, but from this thread you can select posts with a thumbnail by specifying meta_key=_thumbnail_id
in your original query.