ion
ion

Reputation: 1059

Wordpress get id of image(s) used inside post

I would like to get all IDs of images used inside a post.

I know how to get all images attached to a post however I want to retrieve all IDs of attached images that are used inside the post. The only way I can think of is by looking through the_content -> finding all images used -> get IDs from image URL.

Do you think there is a better and more efficient solution.
Again I repeat (just to make it clear :) I need IDs of images that are used inside the post, which means that they are printed out using the_content() function.

Thank you very much ion

Upvotes: 0

Views: 880

Answers (1)

thenetimp
thenetimp

Reputation: 9820

New Answer:

I inserted an image without adding it to a post and as our discussion it does indeed add it as related to the post via parent_post.

Adding it to the post and saving the draft added no additional rows to my database table. I did however notice that it has a class of "wp-image-705" where 705 is the wp_posts record for the image. Therefore it seems the only way currently is to use get_the_content() put it in a variable and use preg_match_all to parse it out via regular expression.

Upvotes: 1

Related Questions