我想要什么?
为我的自定义post类型创建一个post
Api路线有什么问题?
您正在使用什么http方法?
您在使用什么本地apache服务器?
我做了什么?
add_action('init', 'create_custom_post_types');
add_action('admin_menu', 'remove_default_post_types');
function create_custom_post_types()
{
// Apparaten (requests)
register_post_type('apparaten', [
'public' => true,
'show_in_rest' => true,
'label' => 'Apparaten',
'menu_icon' => 'dashicons-smartphone',
'capabilities' => array(
'create_posts' => false
),
'labels' => [
'singular_name' => 'Apparaat'
],
]);
}
function remove_default_post_types()
{
remove_menu_page( 'edit.php' );
remove_menu_page( 'edit-comments.php' );
}
我已经将我的自定义post类型设置为show_in_rest为true,因为我想使用它。但如果我在网址上写了一篇邮递员的文章,我会得到这样的信息:
我做了很多研究,但找不到解决办法。有什么主意吗?
发布于 2020-04-13 11:31:46
我找到了一个解决办法
对于自定义post类型,您需要创建自己的rest路由(只添加一个GET请求)。您可以通过使用wordpress中的"register_rest_route“函数来实现这一点。
https://stackoverflow.com/questions/61097367
复制相似问题