wordpress - Php error "Undefined variable:post" when using "get_post_thumbnail_id($post->ID)" -
i have line of php thumbnail image in custom wordpress widget:
$footer_recent_thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->id), 'footer-recent-thumbnail' );
it produces 2 php errors:
notice: customwidgets.php:75 - undefined variable: post notice: customwidgets.php:75 - trying property of non-object
how can resolve this? same php use thumbnail on blog , doesn't give error there.
my guess code in function, so:
function dosomething($someparams) { // ... $fotoer_recent_thumb = // ..... // ... }
in case, $post
not exist in scope, , must imported adding following line inside function:
global $post;
alternatively, , more cleanly, pass parameter.
Comments
Post a Comment