• 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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • has_post_thumbnail is acting weird, it returns true for every single post

    can you paste the full code of the template (please follow https://codex.www.ads-software.com/Forum_Welcome#Posting_Code ) and post a link to your site?

    Thread Starter vilhjalmurv

    (@vilhjalmurv)

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

    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.

    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.

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

    _

    (@viniciusmassuchetto)

    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 */
    }

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘has_post_thumbnail returns true on every post’ is closed to new replies.