My code looks like:
if ( $query->have_posts() ) {
$j = 1;
while ( $query->have_posts() ) {
$query->the_post();
$bcData[] = array(
'title'=>get_the_title(),
);
$j++;
}
echo json_encode($bcData);
} else {
// no posts found
}
$bcData array outputs(using print_r ):
Array (
[0] => Array ( [title] => Pink Nail Shop 9 )
[1] => Array ( [title] => Pink Nail Shop 8 )
)
When I encode this array to json (using json_encode), the newly created json looks like:
[{"title":"Pink Nail Shop 9"},{"title":"Pink Nail Shop 8"}]
While I need json like this:
[{"shop":{"title":"Pink Nail Shop 9"}},{"shop":{"title":"Pink Nail Shop 8"}}]
Hopefully this makes sense, as I've tried hard to articulate what I am trying to accomplish.
Thanks!
"shop"=>as key.