Support » Fixing WordPress » Can setup & see "Featured Image" on post but has_post_thumbnail() returns 0

  • Resolved Val88

    (@val88)


    My theme sets up the thumbnails in the functions.php file as specified. I see the “Featured Image” option link on the post edit page. So far, so good. I enter the image location and name into the “Featured Image” dialog. The action there is “Insert into post.” The image shows up at the top of the post. This seems good, too. But when I attempt to use the “Featured Image” as a thumbnail using the thumbnail functions, it doesn’t display anything at all.

    Here’s my debug snippet from The Loop
    ————————————–

    <?php if ( has_post_thumbnail($post->ID) ) {
    echo 1;
    } else echo 0; ?>

    —————————————
    This always returns 0. It’s like the meta-data for thumbnail was never saved. I’ve tried re-entering and re-saving the featured images on each post, to no avail. It just doesn’t seem like the thumbnaily-ness is being set, but I don’t know why. Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I enter the image location and name into the “Featured Image” dialog.

    Uh? The idea is that you locate the relevant image, click “Show” and then “Use as featured image”. Within the Loop, all you need to use is:

    <?php if ( has_post_thumbnail() ) the_post_thumbnail();

    Uh? Nice. If you click on the “Featured Image” link at the bottom right of the edit post page it brings up a dialog titled “Featured Image” I guess you’re not familiar with it. Thanks for your help.

    And that’s the dialogue I described above.

    if (has_post_thumbnail() is always false. This is the problem which my debug code illustrates.

    Setting the featured image is not setting the meta data. I think that’s what’s happening, but I don’t know why. I was hoping to find someone who had the same problem and solved it.

    Have you tried:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the Twenty Eleven theme to rule out any theme-specific problems.

    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

    Problem resolved. For anyone else who comes across this problem, in the “Set Featured Image” dialog you must select “From computer” for the image you want to use as the thumbnail. You cannot use “From URL” which references the image rather than uploads it. I don’t think this is mentioned anywhere in the Featured Image/Thumbnail usage spec, but it might be helpful if it was.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can setup & see "Featured Image" on post but has_post_thumbnail() returns 0’ is closed to new replies.