Вопрос

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