Reputation: 7794
How to check efficiently if a given image of a Wordpress blog is already a post thumbnail (featured image) of any of the posts in the Wordpress blog.
Upvotes: 0
Views: 95
Reputation: 7794
Found a solution which seems to do:
function isPostThumbnail($imageId) {
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => '=',
'value' => $imageId
),
)
);
return sizeof(get_posts( $args )) >0;
}
Upvotes: 1