Skip to content

Instantly share code, notes, and snippets.

@jakerb
Created February 13, 2019 14:39
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/f445145ca27047abf3604945fcc9acaa to your computer and use it in GitHub Desktop.
Save jakerb/f445145ca27047abf3604945fcc9acaa to your computer and use it in GitHub Desktop.
Add children to Post Object
<?php
function add_children_to_pages($response) {
foreach($response['posts'] as $index => $post) {
$args = array(
'post_type' => 'app_pages',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'orderby' => 'title',
'order' => 'ASC'
);
$child_pages = new WP_Query( $args );
$post->children = array();
foreach($child_pages as $i => $child) {
$post->children[] = $child;
}
}
return $response;
}
add_filter('appuccino_get_pages_response', 'add_children_to_pages', 10);
?>
<p ng-bind="post.post_title"></p>
<ul>
<li ng-repeat="child in post.children" ng-bind="child.post_title></li>
<ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment