Nobody pointed out I was using ‘$data’ incorrectly.
function dept_cat_api( $request ) {
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'crosspost',
'field' => 'slug',
'terms' => array( $request['dept'] ),
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( $request['cat'] ),
),
),
);
$posts = get_posts( $args );
if ( empty( $posts ) ) return new WP_Error( 'no_posts', 'Invalid term(s)', array( 'status' => 404 ) );
$controller = new WP_REST_Posts_Controller('post');
foreach ( $posts as $post ) {
$response = $controller->prepare_item_for_response( $post, $request );
$data[] = $controller->prepare_response_for_collection( $response );
}
// return results
return new WP_REST_Response($data, 200);
}