Created
December 19, 2016 02:44
-
-
Save JMWebDevelopment/5b516207dfc662205b6e4248556ff802 to your computer and use it in GitHub Desktop.
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
/** | |
* Register the necessary fields to display post information correctly | |
*/ | |
add_action( 'rest_api_init', 'theme_slug_register_rest_fields' ); | |
function theme_slug_register_rest_fields() { | |
register_rest_field( 'post', | |
'comments', | |
array( | |
'get_callback' => 'theme_slug_get_comments', | |
'update_callback' => null, | |
'schema' => null, | |
) ); | |
} | |
/** | |
* Returns the array of comments for a given post | |
* | |
* @param $object | |
* | |
* @param $field_name | |
* | |
* @param $request | |
* | |
* @return mixed, list of comments for a post | |
*/ | |
function theme_slug_get_comments( $object, $field_name, $request ) { | |
return get_comments( array( 'post_id' => $object[ 'id' ] ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment