Skip to content

Instantly share code, notes, and snippets.

@jakerb
Last active September 14, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakerb/0c835150d16c90061578e3125ffb772c to your computer and use it in GitHub Desktop.
Save jakerb/0c835150d16c90061578e3125ffb772c to your computer and use it in GitHub Desktop.
Add posts to MyAppuccino response.
<?php
function mya_response_blog_posts($response) {
/*
* Get 10 posts with the type 'post'
* that are set as published.
*/
$posts = get_posts(array(
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => 10
));
$blog_posts = array();
/*
* Loop through our posts.
*/
foreach($posts as $index => $post) {
$id = $post->ID;
/*
* Use the post's ID as the index,
* this will make querying easier.
*/
$blog_posts[$id] = $post;
}
/*
* Add the posts to the data array
* which is passed to our response.
*/
$response['data']['blog_posts'] = $blog_posts;
/*
* We must return the whole response.
*/
return $response;
}
/*
* Add a filter to modify the pages response before it is sent.
*/
add_filter('appuccino_get_pages_response', 'mya_response_blog_posts', 10);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment