当我在我的WordPress网站上搜索时,我得到以下错误:注意:试图在第20行archive-product.php中获得非对象的属性
php文件中的第20行是
$postid = $wp_query->post->ID;
有什么建议我可以解决这个问题吗?作为参考,第20行前后的直接代码如下:
<?php //Display Page Header
global $wp_query;
$postid = $wp_query->post->ID;
echo page_header( get_post_meta($postid, 'qns_page_header_image', true) );
wp_reset_query();
?>
谢谢你,瑞安
这意味着$wp_query->post
不是一个对象。我没有使用worpress太多,但它看起来像一个帖子必须返回一个空对象。
试着跳过任何空的帖子:
<?php //Display Page Header
global $wp_query;
if(!empty($wp_query->post)){
$postid = $wp_query->post->ID;
echo page_header( get_post_meta($postid, 'qns_page_header_image', true) );
}
wp_reset_query();
?>