Created
          June 18, 2021 15:00 
        
      - 
      
- 
        Save annelyse/54044acd93fe2083dbabf5cc0df39191 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| add_action( 'rest_api_init', 'slug_register_acf' ); | |
| function slug_register_acf() { | |
| $post_types = get_post_types(['public'=>true], 'names'); | |
| foreach ($post_types as $type) { | |
| register_rest_field( $type, | |
| 'acf', | |
| array( | |
| 'get_callback' => 'slug_get_acf', | |
| 'update_callback' => null, | |
| 'schema' => null, | |
| ) | |
| ); | |
| } | |
| } | |
| function slug_get_acf( $object, $field_name, $request ) { | |
| return get_fields($object[ 'id' ]); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment