Created
March 21, 2018 17:51
-
-
Save nandomoreirame/c0eab794adb6d4b1b20f472dbed4c3c1 to your computer and use it in GitHub Desktop.
WordPress API get Post Comment
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 | |
| add_action( 'rest_api_init', 'theme_register_rest_fields' ); | |
| function theme_register_rest_fields() { | |
| register_rest_field( 'post', 'comments', array( | |
| 'get_callback' => 'theme_get_post_comments', | |
| 'update_callback' => null, | |
| 'schema' => null | |
| )); | |
| } | |
| function theme_get_post_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