WordPress 数据库查询代码中断
add_action( 'trash_post', 'producers_xml' );
function producers_xml($post_id){
if($post_id){
$post_type = $wpdb->get_results("SELECT element_type FROM wp_icl_translations WHERE element_id = '".$post_id."'");
if($post_type[0]->element_type == 'post_producer'){
die("Yes");
}
}
在
本地测试此代码(并用硬编码值替换 $post_id)没有问题,但是当我将其放入此函数中时,它会在数据库查询之前中断。我已经检查了 $post_id,它已设置并保存我想要搜索的值。但该查询之后的任何操作都不起作用。我做错了什么?
谢谢
add_action( 'trash_post', 'producers_xml' );
function producers_xml($post_id){
if($post_id){
$post_type = $wpdb->get_results("SELECT element_type FROM wp_icl_translations WHERE element_id = '".$post_id."'");
if($post_type[0]->element_type == 'post_producer'){
die("Yes");
}
}
}
Testing this code locally (and substituting the $post_id with a hard-coded value) is no problem, but when I place it in this function, it breaks right before the database query. I've checked the $post_id and it is set and holds the value I want to search. But anything after that query doesn't work. What am I doing wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保首先全局 $wpdb
Make sure you global $wpdb first