The code I’m using, is outside of WordPress i.e.
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
global $wpdb;
The code that I’m trying to display the post thumbnail (the set featured image) is:
if(has_post_thumbnail($post->ID)){
echo "has a thumb";
get_the_post_thumbnail();
the_post_thumbnail();
the_post_thumbnail('medium');
wp_get_attachment_image_src(get_post_thumbnail_id());
wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
} else {
echo "no thumb";
}
Now it does does correctly display if there is a thumb or not, but doesn’t return the thumb file name or anything at all. I’ve tried all methods I could find and nothing is returned, nor is there any errors returned.
Suggestions, thoughts?
Let’s examine the differences between the working and the not-working code:
has_post_thumbnail( $post->ID )
get_the_post_thumbnail();
The only difference I see is that you’re passing the
$postID
explicitly to the working function, and not passing it to the non-working function. So, try this:You can
var_dump()
orecho
it to verify whether or not you’re getting the correct data returned.get_the_post_thumbnail
, andwp_get_attachment_image_src
return their output, they don’t echo it out.In this case to get the url for a given size:
it may be noted that the thumbnail size will be used if none is specified but I’ve added it to be precise
If you’re in need of further clarification on exactly what is being returned by those functions, and want something stark and outright blatantly visible, I’d suggest something such as:
Though I would recommend you use
error_log
rather thanwp_die
and look at the error log in a text editor, as wp_die is not something you want in production codeedit: -_- debug all the things!!
try: