为什么Muy自定义Gutenberg块返回空的innerHtml和innerContent字段?

问题描述

我已经在api中公开了这些块:

add_action('rest_api_init',function () {

  if ( ! function_exists( 'use_block_editor_for_post_type' ) ) {

    require ABSPATH . 'wp-admin/includes/post.PHP';
  }

  $post_types = get_post_types_by_support( [ 'editor' ] );

  foreach ( $post_types as $post_type ) {

    if ( use_block_editor_for_post_type( $post_type ) ) {

      register_rest_field($post_type,'blocks',['get_callback' => function ( array $post ) {

        $raw_blocks =  parse_blocks( $post['content']['raw'] );

        $supported_blocks = [];

        foreach ($raw_blocks as $raw_block) {

          if( $raw_block['blockName'] ){

            array_push($supported_blocks,$raw_block);

          }

        }

        return $supported_blocks;

      }]);

    }

  }

});

这样注册我的区块:

function register_acf_block_types() {
  // register a testimonial block.
  acf_register_block_type(array(
     'name'              => 'info-picture','title'             => __('Home Info/Picture Block'),'description'       => __('A custom info/picture block.'),'render_template'   => 'template-parts/blocks/info-picture/info-picture.PHP','category'          => 'common','icon'              => 'admin-comments','keywords'          => array( 'info','picture' ),));
}
// Check if function exists and hook into setup.
if( function_exists('acf_register_block_type') ) {
  add_action('acf/init','register_acf_block_types');
}

但是当我对api:http://my.syte/wp-json/wp/v2/pages/8进行GET调用时,我得到了:

            "innerBlocks": [],"innerHTML": "","innerContent": []

我找不到从这些字段中获取数据的方法

我知道了:

"content": {
  "rendered: "the whole HTML of the page..."
}

但是我需要特定自定义块的innerHtml或innerContent。

非常感谢您!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)