Created
February 13, 2019 14:39
-
-
Save jakerb/f445145ca27047abf3604945fcc9acaa to your computer and use it in GitHub Desktop.
Add children to Post Object
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 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); | |
?> |
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
<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