• Resolved Melusine29

    (@melusine29)


    Hello

    I get via <img src="'.get_post_meta($listing-> ID, 'image', true)." /> my picture but I want recovered the right size without having to set the width and height in the image tag ..

    Regards
    Melusine

Viewing 10 replies - 1 through 10 (of 10 total)
  • is this image in your Media Library?

    Thread Starter Melusine29

    (@melusine29)

    Yes, and the right size is powered by WP and is in the upload folder

    Thread Starter Melusine29

    (@melusine29)

    Yes. I tried :

    $attachment_id = $listing->ID;
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    var_dump($image_attributes);
    echo '<img src="'.$image_attributes[0].'" width="'.$image_attributes[1].'" height="'.$image_attributes[2].'">';

    But my var_dump return bool(false) …

    My image is inserted via a custom field

    Where are you getting $listing from?

    Seems that $listing is your post object not attachment object.
    you need to save attachment id in post meta instead of image url then you can use wp_get_attachment_image to get image by passing attachment id and right image size.

    you need to save attachment id in post meta instead of image url

    My thoughts exactly!

    Thread Starter Melusine29

    (@melusine29)

    Seems that $listing is your post object not attachment object.
    you need to save attachment id in post meta instead of image url then you can use wp_get_attachment_image to get image by passing attachment id and right image size.

    Yes $listing is my post object.

    How can I save the attachment id instead of the url? Right now get_post_meta($listing->ID, 'image', true) return the url or the picture.

    you can any of these options

    1. use https://codex.www.ads-software.com/Function_Reference/get_children to get all attachment of post or page.
    2. Assign image to post thumbnail and get it by get the post thumbnail
    3. If your post thumbnail already in use then save in post meta at the time of uploading image if you are using custom uploader
    Thread Starter Melusine29

    (@melusine29)

    I can’t put the image in post thumbnail, I recovered an import.
    Too bad if you can’t do what I want, I’ll put Timthumb ..
    Never mind!
    Thanks for your help anyway

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Size image with get_post_meta’ is closed to new replies.