1

Lets say I have the ID of an image. Is there a way that I get all the posts that have that image as their featured image?

2 Answers 2

2

The featured image is stored as post meta with the key _thumbnail_id, so you could use a meta query to get posts with a specific thumbnail:

$posts = new WP_Query( array( 
    'meta_query' => array(
        array(
            'key'   => '_thumbnail_id',
            'value' => $attachment_id,
        ),
    ),
) );

Where $attachment_id is the ID of the image.

0

I am trying to do the same but for content images, it seems that there is no other way than parsing the content with regex. Featured image is easy, ¿ do you know how to do the same with content attachments?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.