Skip to content

Instantly share code, notes, and snippets.

@thecodepoetry
Created July 6, 2022 05:51
Show Gist options
  • Save thecodepoetry/0a12ae6f1ee146e5159799831c8580db to your computer and use it in GitHub Desktop.
Save thecodepoetry/0a12ae6f1ee146e5159799831c8580db to your computer and use it in GitHub Desktop.
Add album gallery images to REST API
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;
}
@thecodepoetry
Copy link
Author

Please try this code in your child theme functions.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment