未定义的属性:WP_Error:: $name
有人可以帮我解决这个问题吗?尝试使用事件类型作为事件的名称,但它在标题中抛出错误
if (empty($_POST['_tmem_event_name'])){
// phpcs:ignore WordPress.Security.NonceVerification
$_POST['_tmem_event_name'] = get_term(
sanitize_text_field(
wp_unslash(empty($_POST['tmem_event_type']))
),
'event-types'
)->name;
// phpcs:ignore WordPress.Security.NonceVerification
}
Can anyone help me with this please? Trying to use the event-type as the name of the event but it's throwing the error in the title
if (empty($_POST['_tmem_event_name'])){
// phpcs:ignore WordPress.Security.NonceVerification
$_POST['_tmem_event_name'] = get_term(
sanitize_text_field(
wp_unslash(empty($_POST['tmem_event_type']))
),
'event-types'
)->name;
// phpcs:ignore WordPress.Security.NonceVerification
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于那些想要更具体答案的人来说,
empty()
调用是根本问题。empty()
检查提供的变量(本例中为$_POST['term_event_type']
)是否为空并返回true
或假
值。我怀疑这里的意图是这样的:由于您包含了 phpcs 忽略行,我假设您希望坚持编码标准 - 您也可能会收到有关覆盖全局变量的错误。我为你禁用了它。但是,您确实不应该禁用其中任何一个 - 它们的存在是有原因的,并且修复起来非常简单。如果您需要的话,很乐意提供帮助。
For those who want a more specific answer, the
empty()
call is the underlying problem.empty()
checks if the provided variable ($_POST['term_event_type']
in this example) is empty and returns atrue
orfalse
value. I suspect the intent here was something like this:Since you're including a phpcs ignore line, I'll assume you're hoping to stick with a coding standard - you'll also likely be getting an error about overriding global variables. I disabled it for you. However, you really shouldn't be disabling either of those - they exist for a reason and are pretty simple to fix. Happy to help if you need it.