wordpress 我想要输出网页,而不是<!-- wp:paragraph这种古登堡标签,如何解决?

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;

image.png

阅读 536
1 个回答
  1. 从站点里把 Guttenburg 删掉试试
  2. 查一下正常输出的 filter,把它加上
  3. 如果不影响最终网页,这些注释可以忽略
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题