Reputation: 149
i've installed wp-json-rest-api on my Wordpress website and i want to connect my website to an android app. In such a url, it gets all the posts:
http://mywebsite.com/wp-json/posts
On one of the android pages, i want to get ONLY title of posts, nothing more. I mean how should i specify in the url or anywhere else that i just want titles and IDs not all contents of posts? for example in page of each post, i just want to get title, id and content of that post, something like this, where id of the post is 12:
http://mywebsite.com/wp-json/posts?include=title,id,content/12
but in other pages like list of all posts, i want something like this:
http://mywebsite.com/wp-json/posts?include=title,id
what should i do?
Upvotes: 5
Views: 6811
Reputation: 1378
Now Wordpress Rest Api is updated and you can get specific data as you required.
You need to send that field in _fields[] query
For example: http://mywebsite.com//wp-json/wp/v2/posts?_fields[]=id&_fields=title
Upvotes: 3
Reputation: 162
One way to do this would be to create a custom endpoint. This way you can write your own functions and export their results via the REST API. In fact the REST documentation has a sample that does something like what you're asking. See here: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ and just modify their sample to remove the author query logic and just return the list of titles!
Upvotes: 4