篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WP REST API - POST TYPE到JSON相关的知识,希望对你有一定的参考价值。
// http://kaioandrade.com/wp-json/wp/v2/portfolio
add_action( 'init', 'my_custom_post_type_rest_support', 25 );
function my_custom_post_type_rest_support() {
global $wp_post_types;
//be sure to set this to the name of your post type!
$post_type_name = 'planet';
if( isset( $wp_post_types[ $post_type_name ] ) ) {
$wp_post_types[$post_type_name]->show_in_rest = true;
// Optionally customize the rest_base or controller class
$wp_post_types[$post_type_name]->rest_base = $post_type_name;
$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
}
}
以上是关于php WP REST API - POST TYPE到JSON的主要内容,如果未能解决你的问题,请参考以下文章