这里有一种在查询之后过滤帖子的替代方法,使用wp_get_attachment_thumb_url()
返回一个空字符串,以确定帖子是否有缩略图(特色图像)。
//get all the posts however your query does it. simple example when there aren\'t a lot:
$args = array("nopaging" => true);
$posts = (new WP_Query($args))->posts;
//filter the posts array by looking up the thumb_url and seeing if it\'s empty
$posts_without_thumbnails = array_filter($posts, function($post){
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
return ( wp_get_attachment_thumb_url( $post_thumbnail_id ) == "");
} );
如果您需要在查询过程中执行此操作,您可能可以对其进行wordpress筛选或操作,或者拦截
query_posts.