• Resolved Angelo Rocha

    (@angelorocha)


    I create a field file for upload images, i want show this image with size “book_cover”(custom size defined in functions).

    I insert this code in my single.php:

    $cover = wp_get_attachment_image(get_post_meta( get_the_ID(), "_omnicmb_book_cover", 1), 'book_cover');

    But show no data =/

    Var dump in $cover variable show empty.

    Help.

    Sorry for my english.

    https://wordpress.org/plugins/cmb2/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What are you getting back for the get_post_meta() call? It may not be the attachment ID, which the wp_get_attachment_image() function is expecting.

    Thread Starter Angelo Rocha

    (@angelorocha)

    I have not received anything but an empty string, was to return an image with a size “X”

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If you’re not getting anything returned by get_post_meta( get_the_ID(), "_omnicmb_book_cover", 1) then it’s not passing anything into the wp_get_attachment_image() function, and is more the root of the problem. No meta data being returned.

    Thread Starter Angelo Rocha

    (@angelorocha)

    This same documentation: https://github.com/WebDevStudios/CMB2/wiki/Field-Types#file

    When I change the code to:

    $cover = get_post_meta( get_the_ID(), "_omnicmb_book_cover", true);

    It returns the url for the big image, but I can not get the image to a specific size.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If I’m reading that link correctly, changing your key to _omnicmb_book_cover_id will return the needed attachment ID instead of the direct url.

    Worth a try.

    Thread Starter Angelo Rocha

    (@angelorocha)

    Hey Bro!
    Works fine, to return image url in specific size:

    $cover = wp_get_attachment_image_src(get_post_meta( get_the_ID(), "_omnicmb_book_cover_id", 1), 'book_cover');
    
    echo $cover[0];

    CMB2 is awesome!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad to hear that worked itself out finally. Just a matter of piecing the right parts together. Justin’s been good with helping in various ways, including stuff like storing the attachment ID as well

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Field file show no image’ is closed to new replies.