How to get all inline images in post content? [duplicate]

Well you can do this 1 of 2 ways.

$attachments = get_posts(array(
                    'post_type' => 'attachment',
                    'numberposts' => -1,
                    'post_status' => null,
                    'post_parent' => get_the_ID(),
                    'order' => 'ASC',
                    'orderby' => 'id',

                ));

And then manipulate the array to remove duplicates.

Another option would be to apply a content filter, and use a regex to find and grab all img tags within the content.

As far as I know, when you add an image in the visual editor, wp adds it as a post attachment, thus you shouldn’t end up with duplicates via the first method. As for grabbing them in the order they appear, attachments are added sequentially, so grabbing the list by ID should give you the list in the order they were added to the post, but not necessarily in the order they appear in the markup. For that, you’d definitely have to go with the second method of using a content filter.

I don’t personally like the idea of using a content filter for this though, because it might be difficult to write a proper regex to grab the imgs, depending on what all markup is added.

For a regex, something like this:

preg_match('#(<img.*?>)#', $content, $results);

might work. This will dump the results into the $results variable as an array you can work with.