Created
December 30, 2021 21:17
-
-
Save KustomDeveloper/83b63a7435f227661fe8c3378499c8f5 to your computer and use it in GitHub Desktop.
Register custom meta box on custom post type to show in wp rest api
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
/* | |
* Register custom meta box on custom post type to show in wp rest api | |
* | |
* Custom post type must support 'custom-fields' and have the 'show_in_rest' parameter set to true | |
*/ | |
//Custom post type is 'audio' and custom meta box is 'cloud_url' | |
add_action( 'rest_api_init', function () { | |
register_rest_field( 'audio', 'cloud_url', array( | |
'get_callback' => function( $post_arr ) { | |
return get_post_meta( $post_arr['id'], 'cloud_url', true ); | |
}, | |
) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment