这是我的代码
$getcatid = get_the_category($id);
$postisin = $getcatid;
echo print_r($postisin);
此返回:
Array (
[0] => stdClass Object (
[term_id] => 8
[name] => High Net Worth Individuals
[slug] => high-net-worth-individuals
[term_group] => 0
[term_taxonomy_id] => 8
[taxonomy] => category
[description] =>
[parent] => 7
[count] => 1
[object_id] => 1266
[cat_ID] => 8
[category_count] => 1
[category_description] =>
[cat_name] => High Net Worth Individuals
[category_nicename] => high-net-worth-individuals
[category_parent] => 7
)
) 1
我要做的就是抓住[term_id]并将其分配为以后使用的变量。
在这种情况下,'8'我不是PHP最好的,但是自从我使用数组/对象并且无法找到解决方案以来已经有一段时间了。我也丢失了lynda登录信息><请帮助?
您可以这样得到它:
$postisin[0]->term_id
使用循环
foreach ( $postisin as $rows ) {
echo $rows->term_id;
}
,或者,如果您只想回声一个索引,则可以使用
echo $postision[0]->term_id;
尝试以下:
$termId = $postisin[0]->term_id;