Created
July 6, 2022 05:51
-
-
Save thecodepoetry/0a12ae6f1ee146e5159799831c8580db to your computer and use it in GitHub Desktop.
Add album gallery images to REST 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
add_action( 'rest_api_init', 'add_album_gallery_fields' ); | |
function add_album_gallery_fields() { | |
register_rest_field( | |
'dt_gallery', | |
'album_gallery', | |
array( | |
'get_callback' => 'get_album_gallery', // custom function name | |
'update_callback' => null, | |
'schema' => null, | |
) | |
); | |
} | |
function get_album_gallery( $object, $field_name, $request ) { | |
$mediaitems = get_post_meta( get_the_ID(), '_dt_album_media_items', true ); | |
return $mediaitems; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please try this code in your child theme functions.php