Last active
April 6, 2017 23:58
-
-
Save troutacular/703ffcf99b9810812aef17be7e2beac4 to your computer and use it in GitHub Desktop.
Add ACF to WP REST API
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 | |
| /** | |
| * The functions to add all ACF types to the REST API responses. | |
| * | |
| * @link https://developer.wordpress.org/reference/hooks/rest_prepare_post_type/ | |
| * @package theme-name | |
| */ | |
| /** | |
| * Add Options for Posts. | |
| */ | |
| add_filter( 'rest_prepare_post', function( $response ) { | |
| $response->data['acf'] = get_fields( $response->data['id'] ); | |
| return $response; | |
| } ); | |
| /** | |
| * Add Options for Pages. | |
| */ | |
| add_filter( 'rest_prepare_page', function( $response ) { | |
| $response->data['acf'] = get_fields( $response->data['id'] ); | |
| return $response; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment