Skip to content

Instantly share code, notes, and snippets.

@annelyse
Created June 18, 2021 15:00
Show Gist options
  • Save annelyse/54044acd93fe2083dbabf5cc0df39191 to your computer and use it in GitHub Desktop.
Save annelyse/54044acd93fe2083dbabf5cc0df39191 to your computer and use it in GitHub Desktop.
<?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