Skip to content

Instantly share code, notes, and snippets.

@yoren yoren/functions.php Secret

Created Mar 17, 2016
Embed
What would you like to do?
<?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
You can’t perform that action at this time.