Ready to get started?Download WordPress


has_post_thumbnail returns true on every post (8 posts)

  1. vilhjalmurv
    Posted 2 years ago #

    has_post_thumbnail is acting weird, it returns true for every single post, even though most of my posts don't have a featured image set. This is making it impossible for me to return another image for those posts that don't have a featured image.
    These other posts that don't have any featured images have images attached to them inside the content, but they are not defines as featured images. Does has_post_thumbnail return true if there is a image file attached to the post? If so, is there any function that only returns true if the post has a Featured image?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    has_post_thumbnail is acting weird, it returns true for every single post

    can you paste the full code of the template (please follow http://codex.wordpress.org/Forum_Welcome#Posting_Code ) and post a link to your site?

  3. vilhjalmurv
    Posted 2 years ago #

    Here is the code http://pastebin.com/6TWHZmia and here is the image_by_scan function code http://pastebin.com/VZ8RXwCD

  4. keithdevon
    Posted 2 years ago #

    I just had this same problem. To fix it I had to set a featured image and then remove it, for each offending post. Annoying I know, but it worked for me.

  5. artinreality
    Posted 1 year ago #

    Same issue here with has_post_thumbnail() returning TRUE for every post. I was able to resolve it using keithdevon's steps of adding and removing a featured image to necessary posts.

    In my scenario all posts in that custom post type had just been imported into my dev instance of WP. Posts with featured images imported without issue, but those that had no featured image still returned TRUE until I opened each one, set a featured image, and then removed the featured image.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Please post your own topic. This topic is referencing an older version of WordPress.

  7. viniciusmassuchetto
    Posted 1 year ago #

    I solved this by doing:

    if ( strlen( $img = get_the_post_thumbnail( get_the_ID(), array( 150, 150 ) ) ) ) {
        /* display thumbnail */
    } else {
        /* display some other image */
  8. joemerchant2
    Posted 1 year ago #

    Vinicius, thanks so much. I was just working on this issue and you post up a solution 1 hour before me!

Topic Closed

This topic has been closed to new replies.

About this Topic