Last active
September 14, 2018 10:16
-
-
Save jakerb/0c835150d16c90061578e3125ffb772c to your computer and use it in GitHub Desktop.
Add posts to MyAppuccino response.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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