这一条让我感到困惑,因为该代码已经运行了2年,但在最近的WordPress更新到4.7之后,它通过了一个fit。
WordPress正在抛出可捕获的错误致命错误:在函数的第42行,stdClass类的对象无法转换为字符串。php,恰好是这一行:
WHERE {$wpdb->terms}.term_id = {$term_id}
在下面的代码块中。任何帮助都将不胜感激。
// Detects Category ID for category Info custom post type
function wph_wp() {
global $wpdb, $cc_post_id;
$terms = null;
$cc_post_id = null;
if (is_category()) {
$term = get_queried_object();
$terms = array($term->term_id);
} elseif (is_single()) {
$post = get_queried_object();
$terms = wp_get_post_categories($post->ID);
}
if (!empty($terms)) {
foreach ($terms as $term_id) {
$cc_post_id = $wpdb->get_var($wpdb->prepare("
SELECT {$wpdb->posts}.ID FROM {$wpdb->terms}
JOIN {$wpdb->term_taxonomy} ON {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id AND {$wpdb->term_taxonomy}.taxonomy = \'category\'
JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
JOIN {$wpdb->posts} ON {$wpdb->term_relationships}.object_id = {$wpdb->posts}.ID AND post_type = \'category_info\'
WHERE {$wpdb->terms}.term_id = {$term_id}
", ""));
if (!empty($cc_post_id)) {
break;
}
}
}
}