简体   繁体   English

PHP使用Wordpress和JSON API插件获取对象属性不起作用

[英]PHP get object property not working, using Wordpress and JSON API plugin

I'm modifying the WP JSON API core to return just the post titles from a query result object, rather than all the other data. 我正在修改WP JSON API核心,只返回查询结果对象的帖子标题,而不是所有其他数据。

$posts = $json_api->introspector->get_posts($query);
$post_titles = array();
foreach ($posts as $post){
  $post_titles[] =  $post;          //result: {id:0, type:"post", title:"the title" ..}
  $post_titles[] =  $post['title']; //fail
}

When using gettype($posts) I get 'object', and I thought that $obj['key']; 当使用gettype($posts)我得到'对象',我认为$obj['key']; is how to get an object's property in PHP. 是如何在PHP中获取对象的属性。 Any help appreciated, thanks. 任何帮助表示感谢,谢谢。

使用->引用对象属性。

$post->title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM