如何使用JSON Rest API从Wordpress检索私人帖子? [英] How to retrieve private posts from wordpress using JSON rest api?
问题描述
在我的wordpress中,我有公开帖子,草稿帖子和私人帖子. 我安装了WP REST API,以便可以访问另一个域中的帖子.
In my wordpress, I have public posts,draft posts and private posts. I installed WP REST API, so that I can access posts from another domain.
我可以使用以下json命令轻松检索公开帖子
I am able to retrieve the public posts easily with following json command
http://www.example.dev/wp-json/posts?_jsonp=?
complete code
http://codepen.io/anon/pen/YXNrre
但是,我无法检索私人帖子和草稿帖子.我想,我需要传递登录信息
But, I could not retrieve private posts and draft posts. I think, I need to pass login information
我也尝试过
http://www.example.dev/wp-json/posts?type[]=post&_jsonp=?
http://www.example.dev/wp-json/posts?type[]=post&filter[status]=private&_jsonp=?
http://www.example.dev/wp-json/posts?filter[status]=private
如何将身份验证信息从客户端传递到服务器? 我有wordpress登录名和密码.我不懂php.我想我只需要jquery. 以及如何使用JSON从另一个域访问私人帖子? 预先感谢.
How to pass authentication information to server from client side? I have wordpress login and pass word. I don't know php. I think I only need jquery. and how to access private posts from another domain using JSON? thanks in advance.
推荐答案
此处有API文档. http://wp-api.org/#posts_retrieve-posts
There is API documentation here. http://wp-api.org/#posts_retrieve-posts
设置帖子状态的字段称为"post_status",而不仅仅是"status".通常,post_status的默认值为发布".
The field that sets the status for posts is called "post_status", not just "status". The default for post_status is generally "publish".
此外,如果您像前面提到的那样通过了身份验证,则只能使用该字段. http://wp-api.org/guides/authentication.html
Also, you can only use that field if you are authenticated like you mentioned. There's docs for that here http://wp-api.org/guides/authentication.html
这篇关于如何使用JSON Rest API从Wordpress检索私人帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!