删除一些类别(不应该这样做)后,我得到以下错误
可捕获的致命错误:WP\\u error类的对象无法转换为第45行[文件名]中的字符串
这是导致错误的文件。这里有一段摘录(第45行是$output .= \'<a href="\' . $link . \'">\' . $term->name. \'</a>, \';
)
...
foreach($item[\'value\'] as $value) {
$term = get_term($value, $fieldSettings[\'taxonomy\']);
$link = get_term_link($term);
// no option may inerrupt !
if(!$term) {
continue;
}
if(isset($formatterSettings[\'link_bool\']) && $formatterSettings[\'link_bool\']) {
$output .= \'<a href="\' . $link . \'">\' . $term->name. \'</a>, \';
} else {
$output .= $term->name . \', \';
}
}
}
...
如何解决此问题?我重新创建了所有已删除的类别(我备份了它们的名称和slug),但错误仍然存在。谢谢你的帮助!
这是完整的文件
namespace Hydra\\Formatters;
use Hydra\\Builder;
class TaxonomyFormatter extends BasicFormatter {
public function __construct() {
$this->name = \'taxonomy\';
}
public function render(\\HydraFieldViewRecord $viewView, $post) {
$items = $this->getValues($viewView);
if(!$items) {
return $items;
}
$fieldSettings = $viewView->field->attributes;
$formatterSettings = $viewView->settings;
$meta = $viewView->field->meta;
$output = \'\';
foreach ($items as $item) {
if(is_string($item[\'value\'])) {
if($item[\'value\'] == 0) {
continue;
}
$item[\'value\'] = array($item[\'value\']);
}
foreach($item[\'value\'] as $value) {
$term = get_term($value, $fieldSettings[\'taxonomy\']);
$link = get_term_link($term);
// no option may inerrupt !
if(!$term) {
continue;
}
if(isset($formatterSettings[\'link_bool\']) && $formatterSettings[\'link_bool\']) {
$output .= \'<a href="\' . $link . \'">\' . $term->name. \'</a>, \';
} else {
$output .= $term->name . \', \';
}
}
}
$output = trim($output, \', \');
$terms = $output;
$output = \'\';
$output .= \'<div \' . $this->printAttributes($viewView) . \'>\';
if ($meta->prefix) {
$output .= "<div class=\\"field-prefix\\" >" . $meta->prefix . "</div>";
}
$output .= "<div class=field-value>" . $terms . "</div>";
if ($meta->suffix) {
$output .= "<div class=\\"field-suffix\\">" . $meta->suffix . "</div>";
}
$output .= "</div>";
return $output;
}
public function getSettingsForm($parentElement) {
parent::getSettingsForm($parentElement);
$parentElement->addField(\'checkbox\', array(\'link_bool\', __(\'Link to taxonomy page\', \'hydraforms\')))
->setDefaultValue(false);
}
}