Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve private posts from wordpress using JSON 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.

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

I also tried

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

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.

like image 509
srinivas Avatar asked May 30 '15 03:05

srinivas


1 Answers

There is API documentation here. http://wp-api.org/#posts_retrieve-posts

The field that sets the status for posts is called "post_status", not just "status". The default for post_status is generally "publish".

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

like image 95
iridian Avatar answered Nov 15 '22 04:11

iridian