Question

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.

Pas de solution correcte

Autres conseils

Object properties are referenced with ->.

$post->title
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top