我在WP JSON API插件的核心控制器中添加了一个方法,该方法按类别提取帖子,但只获得一个类别数据。请在下面查找代码。
public function module_data() {
global $json_api;
$defaults = array(
\'ignore_sticky_posts\' => true,
\'category_name\' => \'food\');
$posts = $json_api->introspector->get_posts($defaults);
$result = $this->posts_result($posts);
unset($result[\'pages\'], $result[\'count_total\']);
foreach ($result[\'posts\'] as $key) {
$key->thumbnail_image = $key->thumbnail_images[\'thumbnail\']->url;
$key->large_image = $key->thumbnail_images[\'large\']->url;
unset($key->id, $key->type, $key->slug, $key->url, $key->status, $key->title_plain, $key->excerpt, $key->categories, $key->tags, $key->author, $key->comments, $key->custom_fields, $key->comment_status, $key->comment_count, $key->attachments, $key->date, $key->modified, $key->thumbnail, $key->thumbnail_size
, $key->thumbnail_images[\'full\'], $key->thumbnail_images[\'medium\'], $key->thumbnail_images[\'medium_large\'], $key->thumbnail_images);
}
$res[\'food\'] = array_reverse($result[\'posts\']);
$defaults_two = array(
\'ignore_sticky_posts\' => true,
\'category_name\' => \'history\');
$posts_two = $json_api->introspector->get_posts($defaults_two);
$result_two = $this->posts_result($posts_two);
unset($result_two[\'pages\'], $result_two[\'count_total\']);
foreach ($result_two[\'posts\'] as $key) {
$key->thumbnail_image = $key->thumbnail_images[\'thumbnail\']->url;
$key->large_image = $key->thumbnail_images[\'large\']->url;
unset($key->id, $key->type, $key->slug, $key->url, $key->status, $key->title_plain, $key->excerpt, $key->categories, $key->tags, $key->author, $key->comments, $key->custom_fields, $key->comment_status, $key->comment_count, $key->attachments, $key->date, $key->modified, $key->thumbnail, $key->thumbnail_size
, $key->thumbnail_images[\'full\'], $key->thumbnail_images[\'medium\'], $key->thumbnail_images[\'medium_large\'], $key->thumbnail_images);
}
$res[\'history\'] = array_reverse($result_two[\'posts\']);
return $res;
}
输出:
{
"status": "ok",
"food": [
{
"title": "Hyderabad Cuisine",
"content": "<p>Hyderabadi cuisine is a delightful melting pot of Nizam, Turkish, Arabic and Andhra culinary delights. The delicate taste of long, fragrant rice, the lovely aroma of fresh spices, layers of delicious meat and a tinge of saffron come together to create the delectable Hyderabadi Biryani. But, authentic Hyderabadi cuisine goes beyond the much-loved Hyderabadi Biryani and would take your taste buds on a tantalizing journey of flavors offered through age-old recipes and special ingredients from the royal kitchen of Nizams.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Adaa, Taj Falaknuma Palace",
"content": "<p>An opulent symbol of the Nizam’s glory, Adaa is a food connoisseur’s heaven with gastronomic delights served the royal way. The restaurant is decorated with beautifully carved mirrors, life-size portraits of the Nizam ruler, candelabras and sparkling chandeliers. Lunch is an elaborate affair with dishes based on secret recipes from the Nizam’s era. The chef and his team give an impressive brief about the various courses of the meal and present each dish with elan.</p>\\n<p>From succulent kebabs coated in exotic herbs to soft Indian breads, each bite is a delight on its own celebrating the earthy, vibrant and wholesome flavors of Hyderabad. Some popular favorites from this fine dining restaurant are, Rogan Josh (an aromatic lamb dish), Hyderabadi Kacchi Biryani (raw meat and rice are cooked together creating a perfect blend of flavor), Nizam Handi (vegetables or meat cooked in Nizam style), Patthar Ka Gosht (meat marinated overnight and cooked on stone), Dahi Ke Kebab (tangy yoghurt patties that almost melt in the mouth), and Malai Kulfi Faluda (Indian ice cream with vermicelli).</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Paradise",
"content": "<p>With the influence of ancient food delicacies spread across Hyderabad, Paradise restaurant has become an integral part of the Hyderabadi food culture. Dig into the spicy food made from the aromatic ingredients found in the royal kitchen of Mughals. This outlet provides a fine dine experience to its customers with dishes that resonate the hearty, real and wholesome flavors of royal cuisine.</p>\\n<p>The most famous delicacies from this eatery which whips up amazing dishes include the authentic Hyderabadi Chicken / Mutton Biryani (a delicious combination of rice, spices and meat) and Apollo Fish (spiced batter coated fish) & so many more.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Khan Saab",
"content": "<p>The restaurant is famous for its delicacies having a very distinguishable taste and aroma. The eatery has dishes with perfect amalgamation of typical Mughlai flavors with a blend of rich spices. This outlet is famous for conjure delicacies that are rich in taste and texture with exquisite aromas.</p>\\n<p>With an elegant and opulent Peshawari ambience, this restaurant has authentic Hyderabadi food. The eatery offers a range of rare and popular dishes that are made out of exotic spices. Some of the delicacies available from this famous restaurant are Chicken Biryani (chicken cooked with rice and spices), Taar Qorma (royal Indian goat curry), Ghuti Dal ka Shorba (a type of dal / lentil), Paan Halwa (sweet) & many more.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
}
],
"history": [
{
"title": "Hyderabad Cuisine",
"content": "<p>Hyderabadi cuisine is a delightful melting pot of Nizam, Turkish, Arabic and Andhra culinary delights. The delicate taste of long, fragrant rice, the lovely aroma of fresh spices, layers of delicious meat and a tinge of saffron come together to create the delectable Hyderabadi Biryani. But, authentic Hyderabadi cuisine goes beyond the much-loved Hyderabadi Biryani and would take your taste buds on a tantalizing journey of flavors offered through age-old recipes and special ingredients from the royal kitchen of Nizams.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Adaa, Taj Falaknuma Palace",
"content": "<p>An opulent symbol of the Nizam’s glory, Adaa is a food connoisseur’s heaven with gastronomic delights served the royal way. The restaurant is decorated with beautifully carved mirrors, life-size portraits of the Nizam ruler, candelabras and sparkling chandeliers. Lunch is an elaborate affair with dishes based on secret recipes from the Nizam’s era. The chef and his team give an impressive brief about the various courses of the meal and present each dish with elan.</p>\\n<p>From succulent kebabs coated in exotic herbs to soft Indian breads, each bite is a delight on its own celebrating the earthy, vibrant and wholesome flavors of Hyderabad. Some popular favorites from this fine dining restaurant are, Rogan Josh (an aromatic lamb dish), Hyderabadi Kacchi Biryani (raw meat and rice are cooked together creating a perfect blend of flavor), Nizam Handi (vegetables or meat cooked in Nizam style), Patthar Ka Gosht (meat marinated overnight and cooked on stone), Dahi Ke Kebab (tangy yoghurt patties that almost melt in the mouth), and Malai Kulfi Faluda (Indian ice cream with vermicelli).</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Paradise",
"content": "<p>With the influence of ancient food delicacies spread across Hyderabad, Paradise restaurant has become an integral part of the Hyderabadi food culture. Dig into the spicy food made from the aromatic ingredients found in the royal kitchen of Mughals. This outlet provides a fine dine experience to its customers with dishes that resonate the hearty, real and wholesome flavors of royal cuisine.</p>\\n<p>The most famous delicacies from this eatery which whips up amazing dishes include the authentic Hyderabadi Chicken / Mutton Biryani (a delicious combination of rice, spices and meat) and Apollo Fish (spiced batter coated fish) & so many more.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
},
{
"title": "Khan Saab",
"content": "<p>The restaurant is famous for its delicacies having a very distinguishable taste and aroma. The eatery has dishes with perfect amalgamation of typical Mughlai flavors with a blend of rich spices. This outlet is famous for conjure delicacies that are rich in taste and texture with exquisite aromas.</p>\\n<p>With an elegant and opulent Peshawari ambience, this restaurant has authentic Hyderabadi food. The eatery offers a range of rare and popular dishes that are made out of exotic spices. Some of the delicacies available from this famous restaurant are Chicken Biryani (chicken cooked with rice and spices), Taar Qorma (royal Indian goat curry), Ghuti Dal ka Shorba (a type of dal / lentil), Paan Halwa (sweet) & many more.</p>\\n",
"thumbnail_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]",
"large_image": "http://localhost/wp/wp-content/uploads/2016/03/[email protected]"
}
]
}
请帮忙,任何帮助都将不胜感激。提前谢谢。