【发布时间】:2020-02-23 02:07:02
【问题描述】:
我正在尝试从 wordpress API 获取待处理的 cmets/posts。 当我输入这个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 面板中有一条待处理的评论)
【问题讨论】:
-
你试过/cmets?status=pending
-
不,它不起作用。当我查询时:/cmets?status=pending 我得到这个响应:{“code”:“rest_forbidden_param”,“message”:“查询参数不允许:状态", "数据": { "状态": 401 } }
-
状态是“持有”而不是“待定”
标签: javascript wordpress wordpress-rest-api