5

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?

2 Answers 2

4

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!

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.