Search code examples
wordpressadvanced-custom-fieldswordpress-rest-api

Exclude acf properties from posts schema WP REST API


I use plugins: ACF and ACF to REST API. I created group of custom fields, turned on it to show and edit in rest. And setup it to show only post type - post. Ok. I got acf object with my custom fields in rest api as /wp-json/wp/post/1 and /wp-json/acf/v3/posts/1.

But I want to get these properties in only url /wp-json/acf/v3/posts/1, not /wp-json/wp/post/1. In other words, these properties mustn't be in Post Api object.

How can I do it properly? Thanks.


Solution

  • Thanks for using my plugin.

    Please copy and paste the filter below in your functions.php.

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

    Thanks