-
-
Save tolawho/f38970de0e1592c6e5782b7e44575567 to your computer and use it in GitHub Desktop.
Update Custom Post Type Meta Fields with the WordPress 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
<?php | |
register_meta('post', 'custom-field', [ | |
'object_subtype' => 'custom-post-type', | |
'show_in_rest' => true | |
]); |
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
/** | |
* https://stroopwafels.test/wp-json/wp/v2/design-template/ | |
* Make sure to have something like https://github.com/WP-API/Basic-Auth active on your site | |
* Make the request with authentication (Basic Auth and username+password when using the link above) | |
*/ | |
Send as body data (JSON): | |
{ | |
"title": "Test title", | |
"meta": { | |
"custom-field": "test" | |
} | |
} |
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
<?php | |
register_post_type( 'custom-post-type', array( | |
'label' => __( 'Custom Post Type', 'textdomain' ), | |
'show_ui' => true, | |
'menu_icon' => 'dashicons-admin-customizer', | |
'label' => 'Custom Post Type' | |
'supports' => array( 'title', 'thumbnail', 'page-attributes', 'custom-fields' ), | |
'public' => false, | |
'rewrite' => false, | |
'show_in_rest' => true, | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment