【问题标题】:Exclude acf properties from posts schema WP REST API从帖子架构WP REST API中排除acf属性
【发布时间】:2018-03-23 16:07:30
【问题描述】:

我使用插件:ACF 和 ACF to REST API。 我创建了一组自定义字段,将其打开以在休息时显示和编辑。并将其设置为仅显示帖子类型 - 帖子。好的。我在rest api中获得了带有我的自定义字段的acf对象/wp-json/wp/post/1/wp-json/acf/v3/posts/1

但我想在 url /wp-json/acf/v3/posts/1,而不是 /wp-json/wp/post/1 中获取这些属性。换句话说,这些属性不能在 Post Api 对象中。

我怎样才能正确地做到这一点?谢谢。

【问题讨论】:

    标签: wordpress advanced-custom-fields wordpress-rest-api


    【解决方案1】:

    感谢您使用我的插件。

    请将下面的filter 复制并粘贴到您的functions.php 中。

    add_filter( 'acf/rest_api/post/get_fields', function( $item, $request ) {
        if ( is_array( $request ) ) {
            $item = array();
        }
    
        return $item;
    }, 10, 2 );
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 2016-09-04
      • 2022-11-26
      • 2016-01-12
      • 2018-06-24
      相关资源
      最近更新 更多