我正在尝试从wordpress API获取待处理的评论/帖子。当我键入此http://testWeb/wp-json/wp/v2/comments时,仅返回已发布的项目。有没有办法获取待办事项?我想做的是将待处理内容更改为在我的应用程序中发布。
编辑:我已通过验证我已将以下代码添加到wordpress的functions.php中:
wp_enqueue_script('custom_js',get_template_directory_uri() . '/js/custom.js', NULL, 1.0, true);
wp_localize_script('custom_js', 'magicalData',array(
'nonce' => wp_create_nonce('wp_rest'),
));
而且在我的custom.js中,我有:
fetch("http://localhost/testWeb/wp-json/wp/v2/comments?status=pending", {
method: "GET",
headers: {
"Content-Type": "application/json; charset=UTF-8",
"X-WP-Nonce": magicalData.nonce //authorization
}
})
.then(res => res.json())
.then(data => console.log(data)); // t
而且我仍然一无所获(空的对象,尽管我在wordpress面板中有一个待处理的评论)
您必须经过身份验证才能访问待处理的评论
https://developer.wordpress.org/rest-api/reference/comments/