我有一个函数给了我这个错误-Catchable fatal error: Object of class stdClass could not be converted to string in.... blah blah
下面是函数中的一些代码。这是给出错误的最后一行,但我不知道为什么。我试图在project\\u cats分类中显示ID为7的术语。
$html_content .= "<h3>" . rgpost(\'input_1\') . "</h3>"; //Title
$html_content .= "<p><strong>Category:</strong> " . rgpost(\'input_5\') . " | <strong>Budget:</strong> " . rgpost(\'input_3\') . "</p>"; //Category & Budget
$html_content .= "<p>" . rgpost(\'input_4\') . "</p>"; //Description
$html_content .= "" . get_term_by(\'id\', 17, \'project_cats\') . "";
最合适的回答,由SO网友:Eugene Manuilov 整理而成
作用get_term_by
返回对象或数组(基于$output
arg),如果失败则为false。但您将其视为字符串并尝试将其串联。因此,您的代码应该如下所示:
$cat = get_term_by(\'id\', 17, \'project_cats\');
$html_content .= "<h3>" . rgpost(\'input_1\') . "</h3>"; //Title
$html_content .= "<p><strong>Category:</strong> " . rgpost(\'input_5\') . " | <strong>Budget:</strong> " . rgpost(\'input_3\') . "</p>"; //Category & Budget
$html_content .= "<p>" . rgpost(\'input_4\') . "</p>"; //Description
$html_content .= $cat->name;
有关此函数的详细信息,请参阅
codex.