首页 文章

从帖子架构WP REST API中排除acf属性

提问于
浏览
0

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

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

我怎么能正确地做到这一点?谢谢 .

1 回答

  • 1

    感谢您使用我的插件 .

    请复制并粘贴 functions.php 中的filter .

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

    谢谢

相关问题