我正在使用此功能在帖子类型上创建关系:
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_taxonomy
和 wp_term_relationships
表名,因此,不出所料,MySQL 对此表示不满。
在 WordPress 内部,global $wpdb
对象将这些表名称提供给构建查询的函数。如果它的表名称为空字符串,则它尚未初始化。
在调用此函数之前,您可能没有正确设置 WordPress。
关于mysql - Wordpress wp_set_object_terms SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716073/