我正在为我的移动应用程序编写自定义终结点。。
我的输出像this
尝试了一些操作,但获取id、标题和内容的空值。
function my_function($request) {
$data = array();
$id = (int) $request[\'id\'];
$request = array();
if ( empty( $id ) ) {
return new WP_Error( \'rest_post_invalid_id\', __( \'Invalid term id.\' ), array( \'status\' => 404 ) );
}
$query = new WP_Query( array(
\'post_type\' => \'my_posttype_name\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'my_taxonomy_name\',
\'field\' => \'term_id\',
\'terms\' => $id,
)
)
) );
print_r($query);
foreach ($query as $q) {
$data[\'id\'] = $q->posts[0]->ID;
$data[\'title\'] = $q->posts[0]->post_title;
$data[\'content\'] = $q->posts[0]->post_excerpt;
$request[] = $data;
}
return new WP_REST_Response($request, 200);
}
如何获得该值?