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.

$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']; is how to get an object's property in PHP. Any help appreciated, thanks.

没有正确的解决方案

其他提示

Object properties are referenced with ->.

$post->title
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top