WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Image post-format, get id of attached image (7 posts)

  1. veuse
    Member
    Posted 1 year ago #

    I need to get either the image url or image id of the post_format_image, as I want it do do some dynamic image resizing. Anyone know how to do this?

  2. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Your site URL?

  3. veuse
    Member
    Posted 1 year ago #

    Image src or id...

  4. veuse
    Member
    Posted 1 year ago #

    Why has this thread been moved to "How-To and Troubleshooting"? This question is related to the new post-format functionality in wp 3.6

  5. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Is it OK now?

  6. veuse
    Member
    Posted 1 year ago #

    That's better. Thanks.

  7. veuse
    Member
    Posted 1 year ago #

    Seems there is no built-in method for retrieving the image src, but it can be done with a preg_match:

    function get_post_format_image_src($post_id){
    
    	$format_meta = get_post_format_meta($post_id);
    	$match = array();
    	preg_match('/<img.*?src="([^"]+)"/s', $format_meta['image'], $match);
    	return $match[1];
    }

    This will return the image src.

Topic Closed

This topic has been closed to new replies.

About this Topic