mysql - Wordpress wp_set_object_terms SQL 错误

标签 mysql wordpress

我正在使用此功能在帖子类型上创建关系:

private function setObjectTerms($last_insert_id){

      //INSERT course_type/RELATIONSHIP
      wp_set_object_terms($last_insert_id,$this->course_type,'course-type'); 

  }

上面,类(class)类型可以是“免费”或“付费”,$last_insert_id 只是一个数字。

无论如何,我不断收到此错误,并且不知道为什么:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS tr INNER JOIN AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.ob' at line 1]

SELECT tr.term_taxonomy_id FROM AS tr INNER JOIN AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN (15534) AND tt.taxonomy IN ('course-type')

奇怪的是我一直在使用同样的功能,而且它有效。我只是不明白为什么生成的 SQL 不正确。谁能指出我正确的方向?

最佳答案

此失败的查询中缺少 wp_term_taxonomywp_term_relationships 表名,因此,不出所料,MySQL 对此表示不满。

在 WordPress 内部,global $wpdb 对象将这些表名称提供给构建查询的函数。如果它的表名称为空字符串,则它尚未初始化。

在调用此函数之前,您可能没有正确设置 WordPress。

请参阅:How can I initialize wpdb class in a php file?

关于mysql - Wordpress wp_set_object_terms SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716073/

相关文章:

php - 1 表查询 vs 连接多表查询性能

mysql - phpMyAdmin 错误解释

MySQL 像交叉表一样翻转数据

php+mysqli while(false !== ($data = $mysqli_res->fetch_assoc)) 创建无限循环

wordpress - 如何在 WordPress 帖子中仅显示评论作者(未注册)的未批准评论?

css - 如何在 wordpress 中编辑 div 的内联 css?

php - 如何在进入数据库后触发请求?

html - Edge 和 IE 中的背景调整大小

wordpress - "Missing XML tag"Google 网站管理员工具使用 Yoast SEO 工具中的站点地图时出现错误

css - 删除最后一个菜单项的边框