-
-
Save yoren/e01e61b2661b42fd998a to your computer and use it in GitHub Desktop.
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 my_rest_prepare_term( $data, $item, $request ) { | |
$args = array( | |
'tax_query' => array( | |
array( | |
'taxonomy' => $item->taxonomy, | |
'field' => 'slug', | |
'terms' => $item->slug | |
) | |
), | |
'posts_per_page' => 5 | |
); | |
$posts = get_posts( $args ); | |
$posts_arr = array(); | |
foreach ( $posts as $p ) { | |
$posts_arr[] = array( | |
'ID' => $p->ID, | |
'title' => $p->post_title, | |
'content' => array( | |
'rendered' => apply_filters( 'the_content', $p->post_content ) | |
) | |
); | |
} | |
$data->data['posts'] = $posts_arr; | |
return $data; | |
} | |
add_filter( 'rest_prepare_category', 'my_rest_prepare_term', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment