Image exists but has_post_thumbnail says it doesn’t
-
I am at my wits end because it defies all logic. It makes no sense why this isn’t working. I’ve spent a dozen or so hours trying to troubleshoot this. Basically I’m wanting to use the discord webhook, and send an embed rather than use the OpenGraph tags because I want it to look nicer. I have it all working completely but the image won’t appear. I will confess to using a plugin to send to discord because it’s important to be honest. I didn’t write the entire thing. However, in all my hours and hours of testing, I was editing the image function and seeing the result (or lack thereof) through my own code.
I know the data is there because I can:
– see the featured image on the website
– I can see all the data, and run the query for it, within phpmyadminIn case it was a problem with the discord embed I moved to just displaying the return as a string. So no matter what it was returning, it showed e.g. I got “Array” and then tried to iterate through and realised it was just a blank array etc. I double checked everything. In calling this image function, it passed the post_id and I always output that to make sure it was showing correctly, and so I could trace that the featured image was linked properly in the database. Obviously I can’t have thought of everything or I’d have found what was wrong but I must have done nearly 100 tests so far, incremently trying out different things to see where it was breaking.
Initially I used the normal sorts of functions to retrieve it: get_post_thumbnail_id(), wp_get_attachment_image_src() but like has_post_thumbnail I was getting nothing, blank empty arrays etc. So I tried every which way to get the data (I don’t see the point in listing them all, I don’t think I can remember everything I did over the hours), but ultimately as a last resort I did a direct database query – still blank. That’s how I know there’s something really funky going on! Within phpmyadmin the same query brings up data, but in the code it just returns blank.
So I thought, even though everything else showed up (author, title, post description, timestamp etc.) that maybe there was an issue with the postmeta table. Perhaps it was firing off to discord before writing the data.
My next attempt was using the API. To make it simpler I added an action I found on stackoverflow I think to the theme functions, to encode the featured image url direct in the post API. I can pull up the API page and it’s all there. I tested the call to the API by outputting a different row (link so it was the same data format even) – that appeared perfectly, but I use the fimg_url (which I can see in the API page) and nothing, just blank. So I tried calling on the API to the wp:featuredmedia which already existed before I meddled – also blank.
Basically, no matter how I try to bring up the thumbnail data it just returns blank. Which makes NO SENSE because I can see the thumbnail image, I can find all the rows it should be finding in the database, I can trace everything and it’s all exactly how it should be. So why is it returning blank?? I feel like I’m going crazy!
Thank you for your time.
You must be logged in to reply to this topic.