• Resolved galacticpirates

    (@galacticpirates)


    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 phpmyadmin

    In 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I cannot replicate such behavior, so there’s no way for me (or anyone else) to tell you exactly what’s wrong. I can however suggest what you can do to investigate further. The problem is most likely due to interference from a plugin or your theme. As a test, switch to a default theme and deactivate all plugins but the one generating the embed. If the problem persists, then the problem is within the embed generation code itself. If so, you can either debug the code or replace it with your own code. Instead of relying upon WP functions, you could get the image information on a more direct level. You can get the featured image’s attachment ID from the current post’s meta data, keyed “_thumbnail_id”. With the attachment/thumbnail ID, get its post meta keyed “_wp_attachment_metadata”. The returned array includes all size information needed for the image, including a path relative to /uploads/.

    In theory you can get this information using only native PHP, no WP functions are needed at all, but you ought to be able to use lower level WP functions such as get_post_meta() without any problem. If you cannot even get an attachment ID this way, it’s likely that your DB is corrupted and the problem is not the related PHP code.

    Thread Starter galacticpirates

    (@galacticpirates)

    I did try as you suggested. I switched to a totally uncustomised basic theme (the latest 2025). I also deactivated all plugins – it didn’t help, still blank.

    I had already tried your suggestion about getting the image information on the direct level and that hadn’t worked either.

    Anyway I have found a solution! As I said in my initial post my only theory as to how I couldn’t get the information, through any method (direct or function) was “it was firing off to discord before writing the data.” and I’m thinking that was likely true.

    I added this code to delay the discord action:

    wp_schedule_single_event(time() + 5, 'send_to_discord_event', array($post_ID, $post));

    And that did it. I’m still very glad I made this post because while I have found the solution, it drove me insane looking. Usually what I do when troubleshooting is search, and find the reddit/stackoverflow/wordpress support etc. posts where someone else has had the same issue. I found nothing for this, so now I guess I am paying it forward. I hope if anyone else has the same issue they will find this and won’t have the same lengthy nightmare I did.

    Thanks for trying 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.