get image url inside the content in wordpress?

Sounds like you need to do some regular expression on your post content. Which could be done for example like this:

// get the post object
$post = get_post( get_the_ID() );
// we need just the content
$content = $post->post_content;
// we need a expression to match things
$regex = '/src="https://wordpress.stackexchange.com/questions/162402/([^"]*)"https://wordpress.stackexchange.com/";
// we want all matches
preg_match_all( $regex, $content, $matches );
// reversing the matches array
$matches = array_reverse($matches);
echo '<pre>';
// we've reversed the array, so index 0 returns the result
print_r($matches[0]);
echo '</pre>';

Leave a Comment