Created
April 17, 2017 20:13
-
-
Save troutacular/cf429aac17c147015bfe17944b0b7e0e to your computer and use it in GitHub Desktop.
ACF in WP API Response
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