1

如何编辑此条件以仅计算带有缩略图的帖子?

if ( $my_query->have_posts() && ( ( $my_query->post_count ) >= 3 ) )
4

3 回答 3

2

您必须执行循环,因为缩略图关系不会自动解析:

$postsWithThumbs = 0;

while($my_query->have_posts()){
  $my_query->the_post();

  if(has_post_thumbnail())
    $postsWithThumbs++;
}

wp_reset_postdata();

print $postsWithThumbs;
于 2013-02-10T16:02:06.253 回答
2

您必须以不同的方式检查它;

$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
}
于 2013-02-10T16:02:28.937 回答
1

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.

于 2013-02-10T16:04:32.163 回答