所以我试图实现以下内容。如何从查询对象中获取分类术语名称
到目前为止我的代码..
add_filter('wpseo_title', 'vehicle_listing_title');
function vehicle_listing_title($title)
{
if (get_post_type() == 'vehicles')
{
$location = get_the_terms($post->ID, 'vehicle_location');
$model = get_the_terms($post->ID, 'vehicle_model');
$title = $model . 'used cars for sale in' . $location .'on'. get_bloginfo('name');
}
return $title;
}
该代码产生
$location
&$model
是包含以下term_id =>,name=>,slug=>,term_group=>,etc
,所以我想它的name
部分的对象。
我该怎么做?即使没有任何职位分配给查询分类法,我还需要添加什么代码才能返回修改后的
$title
?
要从对象中获取属性,请使用$ object-> property。在你的情况'$ location-> name'。不知道你在第2点是什么意思。 – RST
没问题,但是我在代码中放哪?我在第二点想说的是,上面的代码只有在有汽车列出时才有效。即使没有任何物品清单,我也希望代码仍然有效。我希望这是有道理的。 –