我想在我的 REST API 中显示自定义帖子类型的帖子元。我正在通过 slug 查询帖子
https://www.example.com/wp-json/wp/v2/event?slug=custom-post-slug
add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
function my_post_type_args( $args, $post_type ) {
if ( 'event' === $post_type ) {
$args['show_in_rest'] = true;
// Optionally customize the rest_base or rest_controller_class
$args['rest_base'] = 'event';
$args['post__meta'] = get_post_meta( $post->ID, true );
$args['rest_controller_class'] = 'WP_REST_Posts_Controller';
}
return $args;
}
繁花如伊
相关分类