add_action( 'rest_api_init', 'register_rest_route_test' );
function register_rest_route_test(): void {
register_rest_route(
'v1', '/test',
array(
'methods' => 'GET',
'callback' => function ( $request ) {
$args = array(
'post_type' => 'post',
// 'tax_query' => array(
// array(
// 'taxonomy' => 'people',
// 'field' => 'slug',
// 'terms' => 'bob',
// ),
// ),
);
$response = [];
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$response[] = [
"title" => get_the_title(),
"content" => get_the_content(),
"excerpt" => get_the_excerpt()
];
endwhile;
else:
echo '未找到文章';
endif;
