WordPress.org

Ready to get started?Download WordPress

Forums

wp_get_attachment_image_src and related img functions not giving thumbnails (6 posts)

  1. EjMana
    Member
    Posted 5 years ago #

    This is totally driving me crazy!

    Many people state they use

    $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    foreach( $images as $imageID => $imagePost )
    echo wp_get_attachment_image($imageID, 'thumbnail', false);

    and apparently it works great

    I personnally have

    foreach($myposts as $mypost)
    {
    $imgs =& get_children('post_parent='.$mypost->ID.'&post_type=attachment&numberposts=1&post_mime_type=image');
    if (empty($imgs))
    {
    echo '... default pic';
    }
    else
    {
    foreach($imgs as $attachment_id => $img)
    {
    $image = wp_get_attachment_image_src($attachment_id, "thumbnail", false);
    var_dump($image);
    [...]
    }
    }
    }

    which is basically the same, but whatever parameter I send to wp_get_attachment_image_src as size (mostly "thumbnail" but it is said to be the default so I shouldn't need to pass it), I ALWAYS get the original picture (not resized)!
    And I have checked, the resized picture exists, it is just not fetched
    Nobody else seems to have the same problem which is just so infuriating...
    I could do it by adding myself the dimensions to the result (from toto.jpg to toto234x104.jpg) as it was before (the site has just been upgraded from an older version) but I don't understand why this wouldn't work as nobody else reported this problem
    The previous version of the site had "iMax Width" and "Resize and Save", I got rid of both of them, I tried to make a new article with an attached picture in case it was them storing the previous data in a different way, but it is exactly the same
    Anyone has an idea of what is wrong?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Don't know if this is the answer to your problem but wp_get_attachment_image( $post->ID, 'thumbnail' ) works fine for me. Note that I'm using $post->ID and not the image id.

  3. EjMana
    Member
    Posted 5 years ago #

    I am really puzzled about what you say: the examples I have found in the forum all use attachmentID and not postID, as stated in the example in http://codex.wordpress.org/Function_Reference/get_children

    Anyway with your code

    foreach($myposts as $mypost)	{
    //$imgs = &get_children('post_parent='.$mypost->ID.'&post_type=attachment&numberposts=1&post_mime_type=image');
    $image = wp_get_attachment_image( $mypost->ID, 'thumbnail' );
    var_dump($image);die();
    }

    it doesn't work at all: I get an empty string, and I have also tried wp_get_attachment_image_src and this time received false

    I commented and uncommented the get_children call in case it was interfering, no changes.

    There is actually one person who seems to have the same issue as me 4 months ago
    http://wordpress.org/support/topic/200462?replies=8 (WordPressChina)
    but nobody replied to him/her... But that means it's not something due to the latest 2.8 then

  4. guikubivan
    Member
    Posted 5 years ago #

    Yes, I get the same error on 2.7. It used to work before, so I am guess it may be conflicting with another plugin... ? Will let you know if I find something out.

  5. migueldelosvivos
    Member
    Posted 4 years ago #

    Hi! I recently get this error and I was able to fix it.

    The problem is that WordPress doesn't really generate the thumbnails due a low memory limit: you can upload fully the original picture, but ajax crashes when it tries to generate thumbnails. I didn't realized it until I explored the upload folder and the posts galleries.

    Simply put something like php_value memory_limit 128M inside the .htaccess, and regenerate the thumbnails (or upload all pics again).

  6. DarkGhostHunter
    Member
    Posted 4 years ago #

    BTW, this for using thru a Attachment Loop, not a content loop.

Topic Closed

This topic has been closed to new replies.

About this Topic