【发布时间】:2025-12-13 23:20:04
【问题描述】:
我正在尝试过滤掉帖子类型的标题,我得到了这个
可捕获的致命错误:stdClass 类的对象无法在第 125 行转换为字符串
这是我使用的代码...
add_filter('wpseo_title', 'vehicle_listing_title', 10, 1);
function vehicle_listing_title( $title ) {
global $post;
if ( get_post_type() == 'vehicles' ){
$model = get_queried_object('vehicle_model');
$location = get_queried_object('vehicle_location');
$title = $model . "used cars for sale in" . $location .'on'. get_bloginfo('name'); <---- this is line 125
}
return $title;
}
【问题讨论】:
-
该死,顾名思义,
get_queried_object必须返回一个对象,您只需将其与字符串连接起来,我想不会实现__toString。试试var_dump($model, $location)看看吧。
标签: php wordpress filter fatal-error