Last active
February 15, 2016 17:46
-
-
Save darrenjaworski/408ccc64066c2672cfb5 to your computer and use it in GitHub Desktop.
use custom field suite with wp-api
This file contains 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', 'example_add_cfs' ); | |
/** | |
* Add cfs fields to api call for post type example | |
* Fields will be put in cfs object in json | |
* @param none | |
* | |
* @return null | |
*/ | |
function example_add_cfs() { | |
register_rest_field( 'example', | |
'cfs', | |
array( | |
'get_callback' => 'add_cfs_to_json', | |
'update_callback' => null, | |
'schema' => null, | |
) | |
); | |
} | |
/** | |
* @param array $object Details of current post. | |
* @param string $field_name Name of field. | |
* @param WP_REST_Request $request Current request | |
* | |
* @return mixed | |
*/ | |
function add_cfs_to_json( $object, $field_name, $request ) { | |
return CFS()->get( false, $object[ 'id' ], array( 'format' => 'raw' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment