Skip to content

Instantly share code, notes, and snippets.

@yoren
Created March 17, 2016 03:55
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 yoren/e01e61b2661b42fd998a to your computer and use it in GitHub Desktop.
Save yoren/e01e61b2661b42fd998a to your computer and use it in GitHub Desktop.
<?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