dsgwoh7038 2014-01-22 18:52
浏览 41
已采纳

注意:尝试获取非对象调试错误的属性

When the 404 page is triggered, I get a

Notice: Trying to get property of non-object

on the following lines of code when in debug mode

$custom = get_post_custom($post->ID);

and

$parent_id    = $parent_id_2  = $post->post_parent;

I know this is suppose to happen because the 404 page triggers because the are no post to show in the first place. To get rid of these notices I need to do a check first to see if there is a post to show. My problem is, exactly how do I do it. Any suggestions?

  • 写回答

1条回答 默认 最新

  • dongzhang8475 2014-01-22 18:55
    关注

    I would tend to do something like

    if (isset($post)){
        //action goes here
    }
    

    so the action is only performed if post has been set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计