dorjeduck
dorjeduck

Reputation: 7794

wordpress - check if image is a post thumbnail of any post

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

Answers (1)

dorjeduck
dorjeduck

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

Related Questions